var app = angular.module("myApp", []);
app.controller("myCtrl", function($scope) {
$scope.items = [
{name: 'xxx', amount: 13, years: 2, interest: 2},
{name: 'yyy', amount: 23, years: 1, interest: 3},
{name: 'zzz', amount: 123, years: 4, interest: 4}
];
$scope.sub = function()
{
}
});
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<body ng-app="myApp">
<table ng-controller="myCtrl" border="1">
<tbody>
<tr ng-repeat="item in items">
<td>{{item.name}}</td>
<td><input type=text ng-value="item.years" ng-model="first"></td>
<td><input type=text ng-value="item.amount" ng-model="amount"></td>
<td><input type=submit ng-click="sub()"></td>
</tr>
</tbody>
</table>
</body>
</html>
我上面的片段发生了什么是当用户点击提交按钮时,数据存储在数据库中并返回更新。所以我想要的是,一旦我收到更新,应该删除特定的点击行,或者无论刷新如何,该按钮都应该永久禁用。
我尝试禁用它,但是一旦它收到更新,它就会禁用所有按钮。
请帮我
删除该行或禁用sub()
函数中的按钮。
var app = angular.module("myApp", []);
app.controller("myCtrl", function($scope) {
$scope.items = [
{name: 'xxx', amount: 13, years: 2, interest: 2, disabled: false},
{name: 'yyy', amount: 23, years: 1, interest: 3,disabled: false},
{name: 'zzz', amount: 123, years: 4, interest: 4,disabled: false}
];
$scope.sub = function(name)
{
for(var i=0;i<$scope.items.length;i++){
if($scope.items[i].name === name){
if($scope.disableButton){
$scope.items[i].disabled = true;
}else{
$scope.items.splice(i,1);
}
}
}
}
});
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<body ng-app="myApp">
<label>Disable button (will delete if not checked):
<input type="checkbox" ng-model="disableButton">
</label><br/>
<table ng-controller="myCtrl" border="1">
<tbody>
<tr ng-repeat="item in items">
<td>{{item.name}}</td>
<td><input type=text ng-value="item.years" ng-model="first"></td>
<td><input type=text ng-value="item.amount" ng-model="amount"></td>
<td><input type=submit ng-disabled="item.disabled" ng-click="sub(item.name)"></td>
</tr>
</tbody>
</table>
</body>
</html>
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句