2013-07-16 25 views
0

在最近使用myVar [0] .Key更改的項目中;使用myVar.WhatEver; 這搞砸了一些東西,因爲現在我的.create不會等待webservice響應請求,這意味着像'Guid'這樣的變量(在我的情況下也是'Name')不會傳遞給模板,當我嘗試渲染創建的帖子。Backbone創建不等待json被傳遞(Guid未定義)

我的代碼(有些什麼修改;變量名不匹配原碼):

var self = this; 
var variableNames = this.options.variableNames; 
variableNames.create({ 
      variable1: values.variable1, 
      variable2: values.variable2, 
      variable3: values.variable3 //And so on... 
     }, { 
      wait: true, 
      success: function(variableName) { 
       // Update nav menu list 
       $('#nav').someJqueryMagic() 
         .text(variableName.get('Name')) 
         .data('variableName', variableName.get('Guid')) //This does not work. It is undefined by some reason! 
       )); //This code adds a menu item 

       //Call function for triggering the custom event, pass in the variableName object 
       self.createSuccess(variableName); 

       self.modal.close(); 
       new Interface.Message().success('OK! Du har skapat ett nytt objekt.'); //Swedish rules 
      }, 
      error: function() { 
       new Interface.Message().error('Det gick inte att skapa objektet.'); 
      } 
     }); 
    }, 
    createSuccess: function(variableName) { 
     //Trigger event for rendering the new entry 
     this.vent.trigger('variableName:created', variableName); 

     //This ends up with a table row is rendered. The variableName 
     //object contains Name of who has created the post, a Guid, and 
     //some other information. 
    } 

當我調試的代碼,發送的請求不使用JSON對象答覆,直到創建是完成 - >我猜想太晚了? 有什麼想法發生了什麼?

回答

0

錯誤發生在後端代碼而不是前端。 在後端某處,我們觸發了對請求的200 OK響應,這反過來又觸發了.create()的成功。 我不知道在哪裏或如何,但我們通過恢復一些新編寫的代碼來修復它。