骨干网创建不等待json被传递(Guid未定义)
Backbone create does not wait for json to be passed (Guid is undefined)
在一个项目中,我最近不再使用myVar[0]。Key;使用myVar.WhatEver;这搞砸了一些事情,因为现在我的.create不等待Web服务响应请求,这意味着当我尝试呈现创建的帖子时,像"Guid"这样的变量,在我的情况下还有"Name",不会传递给模板。
我的代码(有些修改了;变量名与原始代码不匹配):
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对象->我想太晚了?你知道发生了什么吗?
错误发生在后端代码中,而不是前端。在后端的某个地方,我们触发了对请求的200 OK响应,这反过来又触发了.create()的成功。我不知道在哪里或如何,但我们通过恢复一些新编写的代码来修复它。
相关文章:
- 为什么“;未定义的“;在JavaScript中结束循环
- 要求未定义JS回调参数
- 如何检查管道中未定义的项目
- TypeError:无法读取属性'推'未定义的JavaScript
- $window.ga在AngularJS事件中未定义
- 未捕获的TypeError无法读取未定义的属性socialsharing
- 为什么grunt contrib connect的中间件选项的第三个参数是未定义的
- 无法获取属性'selectedIndex'的未定义引用或null引用
- 如何消除代码中的未定义和其他问题
- 未捕获的ReferenceError:$未定义
- this.router在AngularJS 2中未定义
- 未捕获的类型错误:无法读取属性'删除'的未定义
- 节点fs.stat名称未定义
- 尝试在PHP中回显输入文本时出现未定义的索引错误
- Jquery未定义函数正在停止其他操作
- AngularJS指令出错-无法读取属性'编译'的未定义
- 这.SOMETHING 总是返回未定义的 - extjs
- 无法获取属性'Id'使用Knockout.js的未定义或空引用API
- 骨干网创建不等待json被传递(Guid未定义)
- jQuery处理程序未定义(handler.guid)