你好我对angularjs很新,需要一些帮助来更新每一行。假设用户从下拉框或复选框中更改任何选项,我需要跟踪它们并在用户单击“提交”时将该数据传递给后端。我怎样才能做到这一点?
var app = angular.module('plunker', []);
app.controller('MainCtrl', function($scope) {
$scope.name = 'Need to update Row that I have changed';
$scope.submitButton = function(){
alert("please help me !!!");
}
$scope.cities = ["Austin",
"Leander",
"RoundRock"];
$scope.data = [{check:'active',firstName:'James',lastName:'Austin',city:'Leander'},
{check:'inactive',firstName:'Niki',lastName:'Jones',city:'Austin'},
{check:'active',firstName:'Amy',lastName:'Parker',city:'RoundRock'}]
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.14/angular.min.js"></script>
<!DOCTYPE html>
<html ng-app="plunker">
<head>
<meta charset="utf-8" />
<title>AngularJS Plunker</title>
<script>document.write('<base href="' + document.location + '" />');</script>
<link rel="stylesheet" href="style.css" />
<script data-require="angular.js@1.5.x" src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.11/angular.min.js" data-semver="1.5.11"></script>
<script src="app.js"></script>
</head>
<body ng-controller="MainCtrl">
<p>Hello {{name}}!</p>
<table>
<thead>
<th>Active</th>
<th>First Name</th>
<th>Last Name</th>
<th> City</th>
</thead>
<tbody>
<tr ng-repeat="d in data">
<td><input type="checkbox" ng-checked="d.check=='active'"/>{{d.check}}</td>
<td>{{d.firstName}}</td>
<td>{{d.lastName}}</td>
<td><select ng-model="d.city" ng-change="showSelectValue(d.city)" ng-options="c for c in cities"></select></td>
</tr>
</tbody>
</table>
<button type="button" ng-click="submitButton()">Submit</button>
</body>
</html>
`我对Angularjs很新,需要帮助更新每一行。
每当用户更改复选框或下拉列表中的值时,我需要跟踪它们并在用户单击保存时将该数据传递给后端。