AngularJS - 装Ajax调用后延迟过滤器,直到过滤器、AngularJS、Ajax

2023-09-13 04:03:23 作者:Les chansons d’amour 情歌

我想知道我怎么能延缓过滤功能,直到加载所有数据通过AJAX调用后。

我想通过数据筛选,但由于他们没有加载,直到AJAX调用我无法筛选其中的一些。有没有办法要么推迟过滤功能或禁用,所有数据被加载后启用它?

更新的

这是数据结构设置的方式是,我做一个AJAX调用并加载不同用户做出帖子的列表。后来,我叫另外两个AJAX调用加载有关用户帐户对每个岗位的信息。

当我设置过滤器为帖+用户信息+帐户信息,我只能通过帖子过滤。不过,我想通过用户帐户信息过滤为好。

我想,如果直到所有数据被加载我禁用过滤器,我可以解决这个问题。

解决方案 Angularjs的学习 未完成

使用 NG-模型加上语法到过滤器结合到所述响应数据来做到这一点。例如:

 <选择NG模型=$ root.listDataNG-包括='my_list'| filterTopTen:$ root.listData要求>< /选择> 

  

许多有状态的过滤器可以仅仅通过揭露隐藏状态作为模型,并把它变成了过滤器的参数转换成无状态的过滤器。

单元测试表明过滤器在下列情况下执行的:

不应以过滤器,除非输入/参数修改

应该重新评估过滤器与非原始输入确实支持的valueOf()的valueOf()价值变动

应始终重新评估与非原始输入滤波器,不支持的valueOf()

不应该与非原始输入确实支持的valueOf()

重新评估过滤器

应始终重新评估与原型创建非原始输入滤波器

参考

AngularJS性能提示

探索角1.3 :状态过滤器

AngularJS来源:parseSpec.js

I want to know how I can delay the filter functionality until after loading all the data through AJAX calls.

I'm trying to filter through data, but I can't filter some of them since they're not loaded until the AJAX calls. Is there a way to either delay the filter functionality or disable and enable it after all data is loaded?

Update

The way that the data structure is set up is that I make an AJAX call and load a list of posts made by different users. Afterwards, I call two other AJAX calls to load information about the user and the account for each post.

When I set up filters for posts + user info + account info, I can only filter through posts. However, I want to filter through user and account information as well.

I think I can fix the problem if I disable filters until all data is loaded.

解决方案

Use ng-model plus the : syntax to bind the filter to the response data to do this. For example:

<select ng-model="$root.listData" ng-include="'my_list' | filterTopTen:$root.listData" required></select>

Many stateful filters can be converted into stateless filters just by exposing the hidden state as a model and turning it into an argument for the filter.

Unit Tests reveal that filters are executed in the following cases:

should not invoke filters unless the input/arguments change

should reevaluate filters with non-primitive input that does support valueOf() when valueOf() value changes

should always reevaluate filters with non-primitive input that doesn't support valueOf()

should not reevaluate filters with non-primitive input that does support valueOf()

should always reevaluate filters with non-primitive input created with null prototype

References

AngularJS Performance Tips

Exploring Angular 1.3: Stateful Filters

AngularJS Source: parseSpec.js