我在表上有3个colums。我的表中没有required
字段。
单击"保存"按钮时,每行应在一个数组中保存为单独的对象。
1.如果未上传文档,可以是空的。
2.检查检查框,应为 true
,否则false
。
3.但名称应在每个对象中。
var app = angular.module('myApp', [])
app.controller('myController', function($scope) {
$scope.listName = [{
'name': 'aaa'
},{
'name': 'bbb'
},{
'name': 'ccc'
}];
$scope.saveDetails = function(doc) {
if ($('#status').is(':checked')) {
doc.status = 'true'
} else {
doc.status = 'false'
}
console.log(doc)
};
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myApp" ng-controller="myController" ng-init="init()">
<table>
<thead>
<tr>
<th>Name</th>
<th>file</th>
<th>status</th>
</tr>
</thead>
<tbody>
<tr ng-repeat='doc in listName'>
<td>{{doc.name}}</td>
<td>
<input type="file" ng-model="doc.file" />
</td>
<td>
<input type="checkbox" ng-model="doc.status" />
</td>
</tr>
</tbody>
</table>
<button ng-click="saveDetails(doc)">save</button>
</div>
有帮助吗?谢谢!
您不需要jQuery方法尝试Follwing:
var app = angular.module('myApp', [])
app.controller('myController', function($scope) {
$scope.listName = [{
'name': 'aaa',
file: "",
status:false
},{
'name': 'bbb',
file: "",
status:false
},{
'name': 'ccc',
file: "",
status:false
}];
$scope.saveDetails = function(doc) {
console.log($scope.listName)
};
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myApp" ng-controller="myController" ng-init="init()">
<table>
<thead>
<tr>
<th>Name</th>
<th>file</th>
<th>status</th>
</tr>
</thead>
<tbody>
<tr ng-repeat='doc in listName'>
<td>{{doc.name}}</td>
<td>
<input type="file" ng-model="doc.file" />
</td>
<td>
<input type="checkbox" ng-model="doc.status" />
</td>
</tr>
</tbody>
</table>
<button ng-click="saveDetails(doc)">save</button>
</div>