【发布时间】:2018-10-10 18:08:09
【问题描述】:
我正在将 JSON 加载到表中。我希望我的“编辑”按钮编辑一行,而我的“编辑选择”只编辑那些被选中的行,但我无法弄清楚。我只设法让它一次编辑所有行。
example.json
{
"example": [
{
"first": "something1",
"second": "one"
},
{
"first": "something2",
"second": "two"
},
{
"first": "something3",
"second": "three"
},
{
"first": "something4",
"second": "four"
}
]
}
index.htm
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="styles.css">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
</head>
<body>
<div ng-app="newApp" ng-controller="newCtrl">
<h1>
<button ng-click="showFunc()">Edit selected</button>
</h1>
<table>
<tr>
<th></th>
<th>Index</th>
<th>First </th>
<th>Second</th>
<th>Edit</th>
</tr>
<tr ng-repeat="iterator in newData.example" ng-show="show">
<td>
<input type="checkbox" />
</td>
<td>{{$index + 1}}</td>
<td>
<input ng-model="iterator.first">
</td>
<td>
<input ng-model="iterator.second">
</td>
<td>
<button ng-click="showFunc()">Save</button>
</td>
</tr>
<tr ng-repeat="iterator in newData.example" ng-show="!show">
<td>
<input type="checkbox" />
</td>
<td>{{$index + 1}}</td>
<td>{{iterator.first}}</td>
<td>{{iterator.second}}</td>
<td>
<button ng-click="showFunc()">Edit</button>
</td>
</tr>
</table>
<script>
var app = angular.module('newApp', []);
app.controller('newCtrl', function ($scope, $http) {
$http.get("example.json")
.then(function (response) {
$scope.newData = response.data;
});
$scope.show = false;
$scope.showFunc = function (index) {
$scope.show = !$scope.show;
}
});
</script>
</body>
</html>
【问题讨论】:
-
请在问题中包含您的代码,而不是在外部网站上。
-
它不会让我造成“太长”,这就是我使用 pastebin 的原因
-
嗯。我尝试对其进行编辑,效果很好。
-
谢谢,我不知道为什么,但它不会让我发布整件事
标签: angularjs checkbox html-table edit