2

问题概述:目前正在编写 Lightning 组件以更新自定义对象上的记录。但是,每次我触发更新(通过 ui:button)时,页面都会冻结,并且我在调试器或控制台中看不到任何错误。无法为我的生活弄清楚为什么它不起作用。

上下文:该组件有许多填充有记录的下拉列表(标签是记录名称)。在下拉列表中选择一个新值并点击“更新”会调用下面的顶点来更改新选定项目上的自定义字段 (Status__c = 'Ready'),然后更新它之前出现的记录 (Status__c = 'Complete)。我在初始化期间在另一个函数中进行了所有的安全和更新检查,所以你不会在这里看到(如果需要,我可以发布完整的代码)。只是试图让更新工作。

如果有人能告诉我我的方式的错误,我将永远感激:]。一直是 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>
4

2 回答 2

4

我认为问题在于您陷入了将客户端和服务器端控制器方法命名为相同的常见陷阱(在本例中为updateMilestones)。尝试更改其中任何一个的名称以使它们独一无二,我希望这会让您运行。

是的,这有一个错误,我们中的许多人一直在大声疾呼要修复它!

此外,我们在这里有一个非常活跃的 Salesforce 特定 Stack Exchange 论坛https://salesforce.stackexchange.com/会受到更多关注 - 特别是如果您使用闪电组件标记您的帖子(例如,我的帐户配置为向我发送在每个带有闪电组件、储物柜服务等标签的帖子上发送电子邮件警报)。

于 2016-12-08T12:10:11.073 回答
0

那可能是javascript导致错误。由于不知道错误很难解决,我建议您调试错误。

  1. 打开调试模式。一个。在设置中,单击开发 > Lightning 组件。湾。选择启用调试模式复选框。C。单击保存。

  2. 在 Chrome 开发人员工具中,选中 Sources 选项卡中的“Pause on Caught Exceptions”复选框。这通常可以帮助找到问题的根源。其他浏览器可能有类似的选项。

  3. 如果要单步执行某些代码,请添加调试器语句。调试器;当您大致了解问题可能发生在哪里时,这很有用。

调试器

https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/debug_intro.htm

于 2016-12-07T08:57:16.937 回答