gpt4 book ai didi

javascript - 保存后立即获取 Backbone

转载 作者:行者123 更新时间:2023-12-02 18:13:58 25 4
gpt4 key购买 nike

如何在保存后立即调用 fetch...我基本上想在成功发布后直接调用 get...

这是代码尝试:

search: function (search) {
searchM = new SearchM();

searchM.save({
channel: this.$('#channel').val(),
week: this.$('#week').val(),
year: this.$('#year').val(),
filter: this.$('#filter').val()
},
{success: listStore()});

function listStore () {
console.log('list it');
searchM.fetch({success: function (result) {
console.log(result);
}});
}

},

最佳答案

编辑

要从 .save 调用获取响应,请使用回调的第一个参数:

function listStore (model, response, options) {
console.log(model.toJSON());
}
<小时/>

您的尝试看起来基本正确,但有一个小错误...success 回调应该传递 listStore 而不带括号:

searchM.save({ ... },
{ success: listStore });

这将函数“listStore”作为回调传递。当您包含括号时,它会立即运行 listStore,并且返回值将被指定为回调(这当然没有意义)。

关于javascript - 保存后立即获取 Backbone ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19471140/

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