gpt4 book ai didi

javascript - 执行 findQuery emberjs 和 ember 数据时取消对 api 的现有调用

转载 作者:行者123 更新时间:2023-11-28 08:10:06 25 4
gpt4 key购买 nike

我有一个可以进行实时搜索的输入字段。它被设置为每次按键时都会执行 store.findQuery 来触发 api 请求。我注意到在使用它时,我需要在执行每个新的 findQuery 时取消对 api 的挂起的 ajax 调用。由于搜索查询已更改,最终会出现大量不相关的请求。有谁知道该怎么做吗?

最佳答案

没有内置的方法可以做到这一点。对于这种类型的使用,ajax 调用本身不会返回给您。我建议消除您的查找请求,以避免发出大量无用的请求。

App.IndexController = Em.Controller.extend({
foo:undefined,
callsToSearch: 0,
actualSearch: 0,
watchFoo: function(){
this.incrementProperty('callsToSearch');
//context, method, time that must elapse before calling method
Em.run.debounce(this, this.doSearch, 300);
}.observes('foo'),
doSearch: function(){
this.incrementProperty('actualSearch');
// do the actual search here
}
});

http://emberjs.jsbin.com/ciyebaqo/1/edit

关于javascript - 执行 findQuery emberjs 和 ember 数据时取消对 api 的现有调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24330310/

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