我是Angular JS的新手,知道基本的功能。我正在努力使用ng-repeat和過濾器選項來通過非唯一鍵獲得所需的輸出。通過鍵角js ng-repeat堆積
我想通過顏色或製作類別在html中顯示汽車。所以期望的結果,我想看到的是(在此情況下,選擇彩色):
Sort by: CarID, Make or **Color**
Blue
Focus
Red
Camry
Mustang
Yellow
LandCruiser
從控制器來的陣列是:
cars: [
{
"carid": 1,
"makeid": 1,
"carname": 'camry',
"color": 'red'
},
{
"carid": 2,
"makeid": 2,
"carname": 'mustang',
"color": 'red'
},
{
"carid": 3,
"makeid": 1,
"carname": 'landcruiser',
"color": 'yellow'
},
{
"carid": 4,
"makeid": 1,
"carname": 'focus',
"color": 'blue'
},
{
"carid": 5,
"makeid": 3,
"carname": 'civic',
"color": 'blue'
}
]
make: [
{
"makeid": 1,
"makeName": 'Toyota'
},
{
"makeid": 2,
"makeName": 'Ford'
},
{
"makeid": 3,
"makeName": 'Civic'
}
]
我試圖用以下HTML,但沒有工作
<div class="car" ng-repeat="car in cars track by color">
<label>{{car.color}}</label>
<div class="subcar" ng-repeat="c in cars filer by car.color">
<label>{{c.carname}}</label>
</div>
</div>
另外有了上面的查詢,我怎麼用Make來替換過濾器中的顏色一旦用戶點擊Make鏈接?
'filer by car.color'?該格式的文檔在哪裏? – Patrick
也許看到這個http://stackoverflow.com/questions/14733136/ng-repeat-filter-by-single-field和過濾器頁面https://docs.angularjs.org/api/ng/filter/filter關於如何應用過濾器。而不是輸入元素,你也可以使用按鈕,下拉菜單,... –