0

配列から選択したものだけを表示したいのですが、それらが別の配列に含まれているが、これを行うことができないように思われる場合、これを行う方法を知っている場合、または別の方法で行う方法の提案がある場合喜んで承ります。

これは私のハンドルバービューです。

    {{#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'
4

2 に答える 2

1

if は if().. のようには機能しません。完全なステートメントを取得して評価するのではなく、ブール値に変換されるプロパティへのパスを取得します。

コレクションビューで 2 つの配列の交差を表示する場合は、arrayController を作成し、その arrayController のコンテンツを、配列の交差を表す計算プロパティにする必要があります。次に、コレクション ビューをその配列コントローラーにバインドします。

これは次のようになります。

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}}
于 2012-05-03T00:21:28.473 に答える
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);
})

http://handlebarsjs.com/expressions.html

于 2012-05-03T01:42:04.210 に答える