0
我使用Ember作为基本博客,并将博客集合加载到商店中。模型的一个属性是标签。即Ember-匹配数组中元素的模型的数据查询
post: {
title: '...',
post_content: '...',
tags: [ 'javascript', 'ember' ]
}
我读过所有关于DS.store的“查找”方法的文档,但我找不到上询问车型在数组中的元素匹配查询任何东西。
任何人都知道你应该怎么做?
编辑:这是我的相关灰烬代码
模板:
<ul class="nav nav-stacked">
{{#each post in controller}}
{{#link-to 'post' post tagName="li"}}<a href="#post">{{post.title}}</a>{{/link-to}}
{{/each}}
</ul>
ROUTE:
App.JsRoute = Ember.Route.extend({
model: function() {
return this.store.find('post');
}
});
控制器:
App.JsController = Ember.ArrayController.extend({
sortProperties: ['creationDate'],
sortAscending: true
});
我试着这样做的途径:
App.JsRoute = Ember.Route.extend({
model: function() {
return this.store.filter('post', function(record){
return record.getEach('tags').indexOf('javascript') > 0;
});
}
});
但我得到了以下错误:
Error while loading route: TypeError {} ember.js:417
Uncaught TypeError: Object [object Object] has no method 'getEach'
我也是在我的控制器,将其过滤收集,其工作的阵列增加了计算性能,但我宁愿筛选职位通过路线中的model
方法。任何帮助完成这条路线将不胜感激。
这里是我的JSON:
{ posts:
[ { __v: 2,
_id: 1,
author: '...',
complete: true,
creationDate: Sun Nov 17 2013 18:20:00 GMT-0800 (PST),
post_content: '...',
title: 'Dissecting JavaScript Objects',
tags: [ 'javascript', ' objects' ] },
{ __v: 2,
_id: 2,
author: '...',
complete: true,
creationDate: Wed Nov 20 2013 20:03:27 GMT-0800 (PST),
post_content: '...',
title: 'How to create basic chainable functions',
tags: [ 'underscore', 'objects' ] }
]
}
感谢您的回复。我并没有真正使用@项目获得代码的第一部分。它看起来更像Ruby而不是Ember。这是做什么的? – EmptyArsenal
对不起,这是代码的API,适用于你的底部。 – Kingpin2k
我已经玩了一点点。这个例子的用法会在模型方法中进入路线吗? – EmptyArsenal