在一个项目中,我最近改变了使用 myVar[0].Key; 使用 myVar.WhatEver; 这搞砸了一些事情,因为现在我的 .create 不等待请求被 web 服务响应,这意味着像“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 对象-> 我猜为时已晚?对正在发生的事情有任何想法吗?