2014-03-02 39 views
0

我在下面的代码中有一个语法错误,我只想要在回调中执行的函数,但我不确定错误是什么。JavaScript回调的正确语法

应接近:

onClickCallback: UpdateBillCycleStatusToCompleted(1) 

<script type="text/javascript"> 
    SP.SOD.executeFunc("callout.js", "Callout", function() { 
     var itemCtx = {}; 
     itemCtx.Templates = {}; 
     itemCtx.BaseViewID = 'Callout'; 
     // Define the list template type 
     itemCtx.ListTemplateType = 101; 
     itemCtx.Templates.Footer = function (itemCtx) { 
      // context, custom action function, show the ECB menu (boolean) 
      return CalloutRenderFooterTemplate(itemCtx, AddCustomCompleteAction, true); 
     }; 
     SPClientTemplates.TemplateManager.RegisterTemplateOverrides(itemCtx); 
    }); 

    function AddCustomCompleteAction(renderCtx, calloutActionMenu) { 
     // Add your custom action 
     calloutActionMenu.addAction(new CalloutAction({ 
      text: "Custom Action", 
      tooltip: 'This is your custom action', 
      onClickCallback: UpdateBillCycleStatusToCompleted(1) 
     } 
     })); 

    // Show the default document library actions 
    CalloutOnPostRenderTemplate(renderCtx, calloutActionMenu); 

    // Show the follow action 
    calloutActionMenu.addAction(new CalloutAction({ 
     text: Strings.STS.L_CalloutFollowAction, 
     tooltip: Strings.STS.L_CalloutFollowAction_Tooltip, 
     onClickCallback: function (calloutActionClickEvent, calloutAction) { 
      var callout = GetCalloutFromRenderCtx(renderCtx); 
      if (!(typeof (callout) === 'undefined' || callout === null)) callout.close(); 
      SP.SOD.executeFunc('followingcommon.js', 'FollowSelectedDocument', function() { 
       FollowSelectedDocument(renderCtx); 
      }); 
     } 
    })); 
    } 

    function UpdateBillCycleStatusToCompleted(itemId) { 
     alert('Completed'); 
     //var clientContext = new SP.ClientContext.get_current(); 
     //var oList = clientContext.get_web().get_lists().getByTitle('Bill Cycles'); 
     //this.oListItem = oList.getItemById(itemId); 
     //oListItem.set_item('Bill Cycle Preparation Status', 'Completed'); 
     //oListItem.update(); 
     //clientContext.executeQueryAsync(Function.createDelegate(this, this.StatusCompletedSucceeded), Function.createDelegate(this, this.StatusCompletedFailed)); 
    } 

    function StatusCompletedSucceeded() { 
     alert('Item updated!'); 
    } 

    function StatusCompletedFailed(sender, args) { 
     alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace()); 
    } 
</script> 
+0

什么是'onClickCallback:UpdateBillCycleStatusToCompleted(1)',为什么它是脚本块? –

+0

你需要*传递*回调函数,这意味着你必须*不要*它 – Bergi

回答

1

除非UpdateBillCycleStatusToCompleted(1)实际上return function() {...}那么你就错了。

onClickCallback: function() {UpdateBillCycleStatusToCompleted(1);} 

这种事情应该工作。

+0

我仍然有这个错误:SyntaxError:Unexpected token} –

+0

没关系!它的工作现在 –