Salesforce Aura组件,如何从闪电传递值:选择到Onchange控制器?

发布于 2025-02-06 07:03:34 字数 970 浏览 3 评论 0原文

我有闪电:我的光环组件中的选择组件。我需要具有“ 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

流年已逝 2025-02-13 07:03:34

我能够从同事那里获得帮助,以防万一对其他人有用:

解决方案:

使用'title'属性保持值:

<lightning:select title="{!container.charge.Id}" value="{!container.charge.Unit_Type__c}" onchange="{!c.handleUnitTypeChange}">

然后,在JS控制器中,将通过:

let title = event.getSource().get("v.title")

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:

<lightning:select title="{!container.charge.Id}" value="{!container.charge.Unit_Type__c}" onchange="{!c.handleUnitTypeChange}">

Then, in the js controller get it via:

let title = event.getSource().get("v.title")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文