问题概述:目前正在编写Lightning组件以更新自定义对象上的记录。但是,每次触发更新时(通过ui:按钮),页面都会冻结,我在调试器或控制台中看不到任何错误。不能为我的生活弄清楚为什么它不起作用。
上下文:该组件有许多下拉列表,这些下拉列表中填充了记录(标签为记录名称)。在下拉列表中选择一个新值并点击“更新”会调用以下顶点来更改新选定项目上的自定义字段(Status__c ='Ready'),然后更新之前发生的记录(Status__c ='Complete)。我在init期间在另一个函数中执行所有安全性和更新检查,因此您不会在此处看到(如果需要,我可以发布完整代码)。只是想让更新起作用。
如果有人能告诉我我的方式错误,我会永远感激:]。一直是stackoverflow的忠实粉丝,并期待着我终于报名参与。感谢大家的时间!
顶点:
@AuraEnabled
public static void updateMilestones(String deployId,Boolean prodChanged,String newProdMile) {
if( prodChanged == true && newProdMile != null ) {
try {
decimal newProdStepNum;
List <Milestone__c> newReadyProdMile = New List<Milestone__c>();
for(Milestone__c mil1:[SELECT id, Status__c, Step_Order__c FROM Milestone__c
WHERE Deployment__c = :deployID
AND id = :newProdMile LIMIT 1]){
mil1.Status__c = 'Ready';
newProdStepNum = mil1.Step_Order__c;
newReadyProdMile.add(mil1);
}
List <Milestone__c> prodMilesComplete = New List<Milestone__c>();
for(Milestone__c mil2:[SELECT id, Type__C, Status__c FROM Milestone__c
WHERE Deployment__c = :deployID
AND Step_Order__c < :newProdStepNum
AND Type__c = 'Production'
AND Status__c != 'Complete'
AND Status__c != 'Revised']){
mil2.Status__c = 'Complete';
prodMilesComplete.add(mil2);
}
update newReadyProdMile;
update prodMilesComplete;
}
catch (DmlException e) {
throw new AuraHandledException('Sorry, the update did not work this time. Refresh and try again please!');
}
}
}
使用Javascript:
updateMilestones : function(component, event, helper) {
// update milestones server-side
var action = component.get("c.updateMilestones");
action.setParams({
deployId : component.get("v.recordId"),
newProdMile : component.find("prod-mile-select").get("v.value"),
prodChanged : component.get("v.prodChanged")
});
// Add callback behavior for when response is received
action.setCallback(this, function(response) {
var state = response.getState();
if (component.isValid() && state === "SUCCESS") {
// re-run the init function to refresh the data in the component
helper.milesInit(component);
// refresh record detail
$A.get("e.force:refreshView").fire();
// set Update Changed Milestones button back to disabled
component.find("updateButton").set("v.disabled","true");
// show success notification
var toastEvent = $A.get("e.force:showToast");
toastEvent.setParams({
"title": "Success!",
"message": "Milestones have been updated successfully."
});
toastEvent.fire();
}
});
// Send action off to be executed
$A.enqueueAction(action);
}
组件:
<aura:component controller="auraMilestonesController_v2"
implements="force:appHostable,flexipage:availableForRecordHome,force:hasRecordId,force:lightningQuickAction">
<ltng:require scripts="{!$Resource.lodash}" afterScriptsLoaded="{!c.doInit}"/>
<aura:attribute name="recordId" type="String" />
<aura:attribute name="prodMiles" type="Milestone__c[]"/>
<aura:attribute name="prodChanged" type="Boolean" default="false"/>
<!-- FORM -->
<div class="slds-col slds-col--padded slds-p-top--large" id="theform">
<form class="slds-form--stacked">
<!-- UPDATE BUTTON -->
<div class="slds-form-element">
<ui:button aura:id="updateButton" label="Update Changed Milestones" press="{!c.updateMilestones}"
class="slds-button slds-button--brand slds-align--absolute-center" disabled="true"/>
</div>
<hr style="color: #005fb2;background-color: #005fb2;"/>
<!-- PRODUCTION -->
<div aura:id="prod-section">
<div class="slds-form-element">
<label class="slds-form-element__label" for="milestone">Production Milestone</label>
<div class="slds-form-element__control">
<div class="slds-select_container">
<ui:inputSelect aura:id="prod-mile-select" class="slds-select" change="{!c.prodChange}">
<option value="" >--Select One--</option>
<aura:iteration items="{!v.prodMiles}" var="m">
<aura:if isTrue="{!m.Status__c == 'Ready'}">
<option value="{!m.id}" selected="true">{!m.Name} ({!m.User_Name__c})</option>
</aura:if>
<aura:if isTrue="{!m.Status__c == 'Not Ready'}">
<option value="{!m.id}">{!m.Name} ({!m.User_Name__c})</option>
</aura:if>
</aura:iteration>
<option value="completeProdMile" id="completeProdMile">All Production Milestones Complete</option>
</ui:inputSelect>
</div>
</div>
</div>
<div class="slds-form-element">
<label class="slds-form-element__label" for="description">Description</label>
<div class="slds-textarea">
<aura:iteration items="{!v.prodMiles}" var="m">
<aura:if isTrue="{!m.Status__c == 'Ready'}">{!m.Description__c}</aura:if>
<!-- <aura:set attribute="else">All production milestones have been completed.</aura:set> -->
</aura:iteration>
</div>
<hr style="color: #005fb2;background-color: #005fb2;"/>
</div>
</div>
<!-- END PRODUCTION -->
</form>
</div>
<!-- / FORM -->
</aura:component>
答案 0 :(得分:4)
我认为问题在于你已陷入同样命名客户端和服务器端控制器方法的所有常见陷阱(在这种情况下为 updateMilestones )。尝试更改其中任何一个的名称以使其唯一,我希望这会让你运行。
是的,有一个错误,我们中的许多人一直在发出非常大的声音来解决这个问题!
此外,我们在此https://salesforce.stackexchange.com/有一个非常活跃的Salesforce特定Stack Exchange论坛,会引起更多关注 - 尤其是如果您使用闪电组件标记您的帖子(例如,我已将我的帐户配置为向我发送电子邮件提醒在每个标有闪电组件,储物柜服务等的帖子上。
答案 1 :(得分:0)
这可能是导致错误的javascript。由于在不知道错误的情况下很难解决,我建议你调试错误。
开启调试模式。 一个。从“设置”中,单击“开发”&gt;闪电组件。 湾选中“启用调试模式”复选框。 C。单击“保存”。
在Chrome开发者工具中,选中“来源”标签中的“暂停捕获例外”复选框。这通常有助于找到问题的根源。其他浏览器可能有类似的选项。
如果要逐步执行某些代码,请添加调试器语句。 调试器; 当您大致了解问题可能发生的位置时,这非常有用。
调试器
https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/debug_intro.htm