store.filter()不像预期的那样工作ember.js(试图搜索模型)
store.filter() not working as expected ember.js (Trying to search models)
我正试图实现一个搜索系统在这里,我有一些麻烦与store.filter()
首先,除了这里,我找不到任何关于store.filter()
方法的好的文档:http://emberjs.com/guides/models/frequently-asked-questions/
所以我使用该页提供的示例作为指导。
这是我的代码
App.ApplicationController = Ember.ObjectController.extend({
isDropdown: false,
actions: {
handle_search: function() {
var search_text = this.get('search_text');
if (search_text) {
this.set('isDropdown', true);
return this.store.filter('procedure', {proc_name: search_text}, function(procedure) {
console.log(procedure);
});
}
}
}
});
但是当我记录返回的东西时,它返回的基本上是每一个模型。而不是没有结果或只有有限的结果
在procedure
之上,它自己不是模型的对象,它是其他的东西。
所以我的问题是如何获得具有字段的实际模型,以及如何确保存储实际上正在过滤结果?
您只需要传入一个函数,该函数为包含记录
返回true/falseApp.IndexRoute = Ember.Route.extend({
model: function() {
return this.store.filter('color', function(item){
return item.get('color')=='red';
});
}
});
http://emberjs.jsbin.com/OxIDiVU/647/edit 如果您想在包含可选查询参数的同时(通过查询查找)回调服务器,下面的示例将调用/colors?color=green
App.IndexRoute = Ember.Route.extend({
model: function() {
return this.store.filter('color', {color:'green'}, function(item){
return item.get('color')=='red';
});
}
});
/**
Takes a type and filter function, and returns a live RecordArray that
remains up to date as new records are loaded into the store or created
locally.
The callback function takes a materialized record, and returns true
if the record should be included in the filter and false if it should
not.
The filter function is called once on all records for the type when
it is created, and then once on each newly loaded or created record.
If any of a record's properties change, or if it changes state, the
filter function will be invoked again to determine whether it should
still be in the array.
Optionally you can pass a query which will be triggered at first. The
results returned by the server could then appear in the filter if they
match the filter function.
Example
```javascript
store.filter('post', {unread: true}, function(post) {
return post.get('unread');
}).then(function(unreadPosts) {
unreadPosts.get('length'); // 5
var unreadPost = unreadPosts.objectAt(0);
unreadPost.set('unread', false);
unreadPosts.get('length'); // 4
});
```
@method filter
@param {String or subclass of DS.Model} type
@param {Object} query optional query
@param {Function} filter
@return {DS.PromiseArray}
*/
相关文章:
- Ember.js:liverload服务器不工作
- Ember数据:如何;映射”;工作
- Emberjs-Ember.Select-valueBinding无法工作
- Ember数据:DS.attr(“数字”)应该如何工作
- Ember reverse物体工作不正常
- 按键事件在 Ember 中未按预期工作
- ember.js将itemController与每个帮助程序一起使用无法按预期工作
- Ember.js被摧毁的观察者不工作
- Broccoli.js 和 Ember-CLI :试图让 SCSS 编译器工作
- Ember.js-让路线和模型协同工作
- Ember手柄嵌套,每个都不工作
- 使用ember.js让classNameBindings与把手中的按钮视图一起工作
- Firefox 21和Ember.js无法工作
- TinyMCE Javascript所见即所得编辑器不能与Ember js一起工作
- store.filter()不像预期的那样工作ember.js(试图搜索模型)
- 如何让Ember.js工作
- 如何使嵌入视图的Ember组件中的数据绑定工作
- Ember控制器依赖解析不能在直接链接上工作
- Ember.js:不能使单向绑定工作
- 如何使Ember Cli Mirage与Ember Simple auth一起工作