0
視圖中使用新行添加到列表如何使用自己的類角
<tr ng-repeat="row in rows" > <td> {{row.ID}} </td> <td> {{row.customer}} </td> <tr>
<button ng-click="quit()">
控制器
$scope.rows = [{
"ID": 12,
"customer": "abc",
},{
"ID": 13,
"customer": "klm",
},{
"ID": 14,
"customer": "xyz",
}];
我添加新行到列表如下(它的工作原理):
Socket.on('delete', function(ID, customer) {
$scope.rows.push({"ID": ID, "customer": customer});
});
$scope.quit = function() { //code ???? }
我的目的是:
(1)每個新行應該與彩色背景(紅色)顯示,並且應該得到一個關閉按鈕(x)的退出新行。點擊此按鈕,backgroundcolor應該將backgroundcolor重置爲none,並且該按鈕應該隱藏。
(2) 所需要的代碼退出與一般的按鈕所有新行(1次點擊=重置所有紅色行背景爲none)
添加到此答案您可以通過在控制器中使用fiters來縮小搜索範圍到新選擇的範圍$ scope.filteredArray = $ filter('filter')($ scope.rows,{「new」:true}); angular.forEach($ scope.filteredArray,function(value,key){ value.new = false; }); –
謝謝@all。這是我的問題,是的。我想擴展這個例子。我怎樣才能做到這一點,反之亦然?這意味着,首先應刪除的行具有綠色背景和一個從列表中刪除它的按鈕。再次按鈕刪除所有。我已經準備好http://plnkr.co/edit/IFdwkj9F4emi6axhAEX6?p=preview你能幫我解決這個問題嗎? –
http://plnkr.co/edit/nauW15kSNrpymk7fcMeR?p=preview – Goodnickoff