我只是想显示只选择一个数组,如果它们包含在另一个数组中但似乎我不能这样做,如果你知道我应该怎么做,或者你有一个如何做的建议我会很高兴听到它。
这是我的车把视图,
{{#each App.User.issues}}
{{#view App.LocationListItemIssueView issueBinding="this" locationBinding="parentView.location"}}
{{#if location.rating[issue.id] != null}}
{{location.rating[issue.id].value}}
{{else}}
{{issue.name}} Not Rated
{{/if}}
{{issue.name}}
{{/view}}
{{/each}}
我得到了他的错误
Uncaught Error: Parse error on line 1:
... {{#if location.rating[issue.id] !=
-----------------------^
Expecting 'ID'
答案 0 :(得分:1)
如果要在集合视图中显示两个数组的交集,则应创建一个arrayController,并使该arrayController的内容成为计算数组交集的计算属性。然后,将您的collectionview绑定到该数组控制器。
这看起来像是:
MyApp.intersectionController = Em.ArrayController.create({
arrayOneBinding: 'MyApp.firstArray',
arrayTwoBinding: 'MyApp.secondArray',
content: function() {
... create and return an array which is the intersection of both arrays ...
}.property('arrayOne.@each', 'arrayTwo.@each').cacheable()
});
如果要渲染数组中的所有项目,但是基于另一个数组以某种方式更改模板,则可以在itemViewClass中执行以下操作:
rating: function() {
return this.getPath('location.rating')[this.getPath(content.id)];
}.property('content', 'location').cacheable();
然后在你看来:
{{#if rating}}
{{rating}}
{{else}}
{{content.name}} not reated
{{/if}}
答案 1 :(得分:0)
这也可以通过Handlebars助手来解决。
Handlebars.registerHelper('compare', function(value, options){
//This would be tweaked to fit your needs.
//I'm checking that a passed in value matches the bound value.
return this.get('content_type') === value ? options.fn(this) : options.inverse(this);
})