導航:首頁 > 凈水問答 > ngrepeat對象過濾

ngrepeat對象過濾

發布時間:2022-02-21 12:28:12

① angularjs如何刪除一個元素內的對象從 ng-repeat 嗎

解決方法 1:
使用 for ... in 循環遍歷一個數組並不是正確的它不只考慮一個數組的元素。既不刪去與數組的一個元素 delete 。這並不改變數組的大小。
一個相當簡單的解決方案是篩選數組 ∶
vm.deleteElements = function(){
vm.classification.forEach(function (classification) {
classification.beneficiaries = classification.beneficiaries.filter(function(beneficiary) {
return !beneficiary.selected;
});
});
}

或如果瀏覽器支持 ES6:
vm.deleteElements = function(){
vm.classification.forEach( classification =>
classification.beneficiaries = classification.beneficiaries.filter(beneficiary => !beneficiary.selected)
);
}

② angularjs 怎麼用多個多選框來控制ngrepeat的一個篩選

<!doctypehtml>
<html>
<head>
<metacharset="utf-8">
<title>test</title>
<scriptsrc="angular.js"></script>
<script>
varmyApp=angular.mole("myApp",[]);
myApp.filter('myfilter',function(){
returnfunction(input,toggle){
vartmp=[];
angular.forEach(input,function(value,key){
switch(toggle){
case'a':
if(value>0)
tmp.push(value);
break;
case'b':
if(value>2)
tmp.push(value);
break;
case'c':
if(value<4)
tmp.push(value);
break;
default:
tmp=input;
}
});
returntmp;
};
});
myApp.controller("testCtrl",function($scope){
$scope.items=[0,1,2,3,4];
$scope.toggle='';
});
</script>
</head>

<body>
<divng-app="myApp">
<divng-controller="testCtrl">
<ul>
<ling-repeat="iteminitems|myfilter:toggle">{{item}}</li>
</ul>
<inputtype="checkbox"ng-model="toggle"ng-true-value="'a'"/>a
<inputtype="checkbox"ng-model="toggle"ng-true-value="'b'"/>b
<inputtype="checkbox"ng-model="toggle"ng-true-value="'c'"/>c
</div>
</div>
</body>
</html>

③ AngularJS在ng-repeat內使用ng-model出現哪些問題

有一些問題:
1.ng-model="obj.qqs[$index]"應該是ng-model="qq"這個就可以解決focus消失的問題。
2.一般不把primitivetype的變數作為ng-model,這里可以用literalobject。
3.如何通過按鈕保存,用ng-click即可。
4.Style的問題。用'controllerasctrl'的語法,避免在controller裡面使用$scope。

④ 有關angularjs中ng-repeat循環中ng-model的問題,是怎麼解決的

Texeure是在全局scope下面的,而repeat裡面有自己的scope,這個scope「繼承」全局的scope。
input的model應該使用repeat里的scope有效的變數。

⑤ angular filter 對數組過濾時,排除arr怎麼做

js:
$scope.arr = [
["212","上","下","左","右"],
["12","1","2","3","4"],
]

html:
<input type="text" ng-model="text">

<tr ng-repeat="dataTr in arr | filter:text">
<td ng-repeat="dataTd in dataTr">
<ng-switch on="$first">
<span ng-switch-when="true">{{index+1}}</span>
<span ng-switch-default>{{dataTd}}</span>
</ng-switch>
</td>
</tr>

⑥ ng-repeat 怎麼實現一次性數據綁定

定義了一個ng-repeat的ng-model雙向綁定輸入框
<ul>
<li ng-repeat="listVed in listVeds">
<div class="row">
<div class="col-xs-3"><input type="text" class="form-control" ng-model="listVed.lastName" placeholder="Employee No"></div>
</div>
</li>
</ul>

⑦ angularjs 可以從ng-repeat中循環出五條數據嗎

循環輸出列表很多項目在web服務端做,前端做好模版後後端寫jsp代碼,雙方需要緊密合作,分清責任。有些項目由後端提供restful方法,前端用ajax調用自己循環,這種一般是大把的jquery拼字元串,太不直觀,有人搞出了js模板,也沒好到哪裡去。
用AngularJS就爽多了,語法和JSP類似:

?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45

<!doctype html>
<html ng-app>
<head>
<meta charset="utf-8">
<title>ng-repeat directive</title>
</head>
<body>
<table ng-controller="CartController">
<caption>我的購物車</caption>
<tr>
<th>序號</th>
<th>商品</th>
<th>單價</th>
<th>數量</th>
<th>金額</th>
<th>操作</th>
</tr>
<tr ng-repeat="item in items">
<td>{{$index + 1}}</td>
<td>{{item.name}}</td>
<td>{{item.price | currency}}</td>
<td><input ng-model="item.quantity"></td>
<td>{{item.quantity * item.price | currency}}</td>
<td>
<button ng-click="remove($index)">Remove</button>
</td>
</tr>
</table>

<script src="../lib/angularjs/1.2.26/angular.min.js"></script>
<script>
function CartController($scope) {
$scope.items = [
{name: "雷柏(Rapoo) V500 機械游戲鍵盤 機械黃軸", quantity: 1, price: 199.00},
{name: "雷柏(Rapoo) V20 光學游戲滑鼠 黑色烈焰版", quantity: 1, price: 139.00},
{name: "AngularJS權威教程", quantity: 2, price: 84.20}
];

$scope.remove = function (index) {
$scope.items.splice(index, 1);
}
}
</script>
</body>
</html>

ng-repeat指令生命在需要循環內容的元素上,items和控制器上的變數名對應,item是為數組中單個對象起的別名。$index可以返回當前引用對象的序號,從0開始,另外還有$first、$middle、$last可以返回布爾值,用於告訴你當前元素是否是集合中的第一個中間的最後一個元素。

⑧ 如何在ng-repeat遍歷的元素中動態設置樣式

<html ng-app="myApp">
<head lang="en">
<meta charset="UTF-8">
<title></title>
<script src="js/angular.js"></script>
</head>
<body ng-controller="myCtrl">
<input type="checkbox" ng-model="isAgreen"/>同意?
<script>
var app=angular.mole('myApp',['ng']);
app.controller("myCtrl",function($scope){
$scope.$watch("isAgreen",function(){
console.log($scope.isAgreen);
});

});
</script>
</body>
</html>
<img src="http://img.blog.csdn.net/20161103195723492?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />
</span>
這段代碼是在沒數據的時候可以直接在控制台列印出true或false。

[html] view plain
<span style="color:#006600;"><!DOCTYPE html>
<html ng-app="myApp">
<head lang="en">
<meta charset="UTF-8">
<title></title>
<script src="js/angular.js"></script>
</head>
<body ng-controller="myCtrl">
<table>
<thead>
<tr>
<th>請選擇</th>
<th>姓名</th>
<th>生日</th>
</tr>
</thead>
<tbody>
<span style="color:#FF0000;"><tr ng-repeat="obj in data">
<td><input type="checkbox" ng-model="isAgreen" />同意?</td></span>
<td>{{obj.name}}</td>
<td>{{obj.age}}</td>
<td>{{$index}}</td>
</tr>
</tbody>

</table>

⑨ angular 中ng-repeat能不能遍歷指定順序

能呀,後面加個Order by 就好了

⑩ angular中用ng-repeat創建的元素怎麼獲取其中某幾個

通過寫過濾器來獲取其中某幾個。

比如

<!DOCTYPEhtml><html><head><metacharset="utf-8"><scriptsrc="http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"></script></head><body><divng-app="myApp"ng-controller="namesCtrl"><p>輸入過濾:</p><p><inputtype="text"ng-model="test"></p><ul><ling-repeat="xinnames|filter:test|orderBy:'country'">{{(x.name|uppercase)+','+x.country}}</li></ul></div><scriptsrc="namesController.js"></script></body></html>

閱讀全文

與ngrepeat對象過濾相關的資料

熱點內容
維克斯每年生產多少濾芯 瀏覽:802
彩潤牌空氣凈化器質量怎麼樣 瀏覽:468
凈水器軟軟管如何安裝 瀏覽:312
山地生活污水怎麼處理 瀏覽:487
廢水處理系統簡易圖 瀏覽:335
飲水機老加水怎麼辦 瀏覽:357
小區飲水機卡怎麼錢一下沒有了 瀏覽:624
蒸餾水裡面有可溶雜質嗎 瀏覽:444
蒸餾水過期了還可以敷臉嗎 瀏覽:513
凈水機是什麼價格 瀏覽:992
血濾超濾率計算 瀏覽:747
污泥提升泵規范 瀏覽:305
IE瀏覽器下載提升重新啟動 瀏覽:83
油鋸空氣濾芯怎麼安裝 瀏覽:407
桑德長沙鄉鎮污水處理廠 瀏覽:996
污水設備凍土埋深要求 瀏覽:1000
玫瑰純露蒸餾要多少個小時 瀏覽:344
醫用聚丙烯樹脂的優勢 瀏覽:51
新軒逸換空調濾芯蓋子怎麼打開 瀏覽:86
深圳家用凈水機多少錢 瀏覽:863