我正在製作一個瀏覽頁面,用戶可以在其中查看我站點搜索構面的頂部術語(我正在使用ElasticSearch/Tire)。我創建了一個對象數組,一個標題和我需要搜索的格式的參數。我想遍歷數組並顯示標題,然後顯示每個方面的搜索結果。起初,我嘗試在控制器中使用for循環遍歷facet_selections
,但這看起來並不像Angular方式。所以現在我試圖在迭代中使用ng-repeat,但我不確定如何將視圖中的參數傳遞給控制器。我閱讀了所有的指令,我看不出合適的,這讓我覺得我可能一起走錯了路。如何將變量從視圖傳遞到作用域使用ngRepeat
下面是一個簡單的控制器:
$scope.facet_selections=[{name:"Collection", value: "collection_title", term: "collectionTitle"}, {name:"Series", value: "series_title", term: "seriesTitle"}, {name:"Episode", value: "episode_title", term: "episodeTitle"},];
$scope.frequency=Frequency.query({facet: facet}).then(function(data) {
$scope.topterms=data.facets[term].terms;
})
而這裏的HTML:
<div class="browse" ng-repeat="object in facet_selections" ng-init="var term={{object.term}}">
<h4> {{object.name}} </h4>
<ul>
<li ng-repeat="term in topterms"> {{term.term}} ({{term.count}})</li>
</ul>
</div>
什麼說法是你想通過? – Fresheyeball
我試圖將'facet'(facet_selections.value)和'term'(facet_selections.term)傳遞給$ scope.frequency。 –