我创建了一个闪电组件,闪电记录编辑表格和几个字段。写了一个Javascript方法,这样当我将第一个字段更改为特定值时,第二个字段就会更新。以下是我的代码。
<aura:component implements="force:appHostable">
<aura:attribute name='test' type='String'/>
<lightning:recordEditForm
aura:id="editForm"
objectApiName="Case"
recordTypeId="{XXXXXXXXXXXXX}">
<div class="slds-col slds-size_1-of-2 slds-p-around_x-small">
<lightning:inputField aura:id="subject" fieldName="Subject" onchange="{!c.subjectChanged}"/>
</div>
<div class="slds-col slds-size_1-of-2 slds-p-around_x-small">
<lightning:inputField aura:id="description" value="{!v.test}" fieldName="Description"/>
</div>
</lightning:recordEditForm>
</aura:component>
以下是Controller代码
({
subjectChanged : function(component, event, helper) {
var subjectValue = component.find("subject").get("v.value");
if(subjectValue === "U") {
//var descriptionValue = component.find("description");
//descriptionValue.set("v.value","User");
component.set('v.test','User');
}
}
})
每当用户将主题字段更新为U时,我希望将描述设置为用户。有什么想法吗?
来自文档:https://developer.salesforce.com/docs/component-library/bundle/lightning:inputField/documentation
.....假设有未保存的更改不应被覆盖。如果您希望能够覆盖用户更改,可以使用lightning:input而不是....
我找到了解决方法。
您可以将inputField
值绑定到aura:attribute
,然后设置aura:attribute
的值。这对于对象上的查找字段特别有用,其中使用lightning:input
失去功能。
例:
<aura:attribute name="myFieldValue" type="string"/>
<lightning:recordEditForm objectApiName="MyObject__c"
onload="{!c.handleLoad}"
onsubmit="{!c.handleSubmit}"
onsuccess="{!c.handleSuccess}"
onerror="{!c.handleError}">
<lightning:inputField fieldName="MyLookupField__c" value="{!v.myFieldValue}"/>
</lightning:recordEditForm>
Javascript控制器:
somethingHappened: function(newDataValue){
component.set("v.myFieldValue", newDataValue);
}