gpt4 book ai didi

backbone.js 集合获取 - 既不会触发成功也不会触发错误函数

转载 作者:行者123 更新时间:2023-12-01 12:51:42 26 4
gpt4 key购买 nike

在下面的代码中,我看到集合初始值设定项触发了。我还可以根据调整数据库命中次数的服务器端查询模块,使模型初始化程序触发不同的次数,因此我确信我的提取正在命中服务器。但是,获取后我从未收到警报。有人可以纠正我肯定是错误的地方吗?

$(function () {

Person = Backbone.Model.extend({
initialize: function () {
alert("Model Init");
}
});

PersonList = Backbone.Collection.extend({
model: Person,
url: '/Tfount_Email/Email/SOAInbox',
initialize: function () {
alert("Collections Init");
}
});

var personlist = new PersonList;

/*
personlist.fetch().complete(function () {
alert("done");
});
*/

personlist.fetch(
{
error: function () {
alert("error!!");
}
},
{
success: function () {
alert("no error");
}
}
);



});

最佳答案

给你。

$(function () {
var Person = Backbone.Model.extend({
initialize: function () {
alert("Model Init");
}
}),
PersonList = Backbone.Collection.extend({
model: Person,
url: '/Tfount_Email/Email/SOAInbox',
initialize: function () {
alert("Collections Init");
}
}),
personlist = new PersonList();

personlist.fetch({
error: function () {
alert("error!!");
},
success: function () {
alert("no error");
}
}).complete(function () {
alert("done");
});
});

注意事项:

  • 我为 PersonPersonList 添加了 var 关键字,你忘记了。
  • fetch() 返回一个 jQuery XHR 对象。您应该将 complete 回调与调用绑定(bind)在一起。
  • fetch() 接受一个选项散列,而不是多个。

关于backbone.js 集合获取 - 既不会触发成功也不会触发错误函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12021699/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com