Salesforce Aura组件,如何从闪电传递值:选择到Onchange控制器?
我有闪电:我的光环组件中的选择组件。我需要具有“ thangeunittypechange”的Onchange方法,可以访问{!container.charge.id}值。我尝试了几种不同的方法来做到这一点,但是到目前为止什么都没有。以下是我尝试将其设置为Aura:ID的一种尝试,但是这似乎不起作用,因为它似乎是Aura:ID只能是硬编码的字符串值,而不是来自变量的值。想知道是否有人对此有任何想法?感谢您的帮助。
其他上下文:这是在循环范围内的,因此{!container.charge.id}是循环列表的变量。
CMP文件:
<lightning:select aura:id="{!container.charge.Id}" value="{!container.charge.Unit_Type__c}" onchange="{!c.handleUnitTypeChange}">
<option text="Select" value=""/>
<aura:iteration items="{!v.pickListChargeUnitType}" var="option" indexVar="key">
<option text="{!option.value}" value="{!option.key}" selected="{!option.key==container.charge.Unit_Type__c}" />
</aura:iteration>
</lightning:select>
JS:
handleUnitTypeChange: function (component, event, helper) {
let localId = event.getSource().getLocalId();
}
I have a lightning:select component in my aura component. I need to have the onchange method, 'handleUnitTypeChange', be able to access the {!container.charge.Id} value. I have tried a few different ways of doing this but nothing is working so far. Below is one attempt I made to set it as the aura:id but this does not work as it seems aura:id can only be a hard-coded string value, not a value from a variable. Was wondering if anyone had an idea on this? Thanks for any help.
Additional context: this is within a loop, so {!container.charge.Id} is a variable from looping over a list.
cmp file:
<lightning:select aura:id="{!container.charge.Id}" value="{!container.charge.Unit_Type__c}" onchange="{!c.handleUnitTypeChange}">
<option text="Select" value=""/>
<aura:iteration items="{!v.pickListChargeUnitType}" var="option" indexVar="key">
<option text="{!option.value}" value="{!option.key}" selected="{!option.key==container.charge.Unit_Type__c}" />
</aura:iteration>
</lightning:select>
js:
handleUnitTypeChange: function (component, event, helper) {
let localId = event.getSource().getLocalId();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我能够从同事那里获得帮助,以防万一对其他人有用:
解决方案:
使用'title'属性保持值:
然后,在JS控制器中,将通过:
I was able to get help from a colleague on this one so posting this in case it's useful to others:
Solution:
Use the 'title' attribute to hold the value:
Then, in the js controller get it via: