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對象答覆,直到創建是完成 - >我猜想太晚了? 有什麼想法發生了什麼?