3

選択したカテゴリに基づいて要素を印刷する配列があります

<li class="thumbnail" ng-repeat="temp in templates| filter:{temp.category_id :       selectedCategoryId }:true">

テンプレートは次のようになります。

[{"id":"1","account_id":null,"category_id":"1","name":"Blue","thumbnail":"placehold.it/210x300","category_name":"test"},{"id":"2","account_id":null,"category_id":"1","name":"Red","thumbnail":"placehold.it/210x300","category_name":"test"},{"id":"3","account_id":null,"category_id":"2","name":"Green","thumbnail":"placehold.it/210x300","category_name":"test again"}]

助けてくれてありがとう !

編集: 追加の条件、つまり temp.category_id == null を追加したかったのですが、すべて表示します。

4

2 に答える 2

2

フィルターで temp を再度指定する必要はありません。

変化する

 filter:{temp.category_id : selectedCategoryId }:true

 filter:{category_id : selectedCategoryId }:true

これが機能するフィドルです: http://jsfiddle.net/Sqq3s/

于 2013-11-08T22:38:01.857 に答える
0

フィルターは次のようにする必要があります。

<li ng-repeat="temp in templates | filter:{category_id : selectedCategoryId}:true"> ... </li>

書き込みは、オブジェクト内のプロパティ(プロパティとしては無効な名前であり、 と読む必要があります)filter: {temp.category_id : selectedCategoryId}を探します。ただし、プロパティを探したいとします。temp.category_id'temp.category_id'tempcategory_id

于 2013-11-08T22:35:50.720 に答える