我的數據集正在返回員工列表。我試圖使用第一個索引中的字段構建我的表單來添加新員工。我正在努力閱讀表單字段數據以添加新員工。小提琴在這裏:http://jsfiddle.net/nicktest2222/AB5Yw/2/AngularJS - 表格數據
任何幫助將不勝感激。提前致謝。
HTML
<form ng-submit="addTodo()">
<span ng-repeat="t in todos[0].Collection.InputList">
<label>{{t.DisplayName}}</label>
<input type="text" name="{{t.FieldName}}"><br>
</span>
<br>
<input class="btn-primary" type="submit" value="Add">
</form>
JS
function TodoCtrl($scope) {
$scope.todos = [{
"Header": "Chris Morgan",
"Collection": {
"InputList": [{
"FieldName": "dpFname",
"DisplayName": "First Name",
"Required": "1",
"AllowEdit": "1",
"TabOrder": "1",
"InputType": "TEXTBOX",
"Style": "",
"Validate": "",
"InputMask": "",
"Options": [],
"Value": "Chris"
}, {
"FieldName": "dpMname",
"DisplayName": "Middle Name",
"Required": "0",
"AllowEdit": "1",
"TabOrder": "2",
"InputType": "TEXTBOX",
"Style": "",
"Validate": "",
"InputMask": "",
"Options": [],
"Value": ""
}, {
"FieldName": "dpLname",
"DisplayName": "Last Name",
"Required": "1",
"AllowEdit": "1",
"TabOrder": "3",
"InputType": "TEXTBOX",
"Style": "",
"Validate": "",
"InputMask": "",
"Options": [],
"Value": "Morgan"
}]
}
}];
$scope.addTodo = function() {
$scope.todos.push({
Header: $scope.dpFname + " " + $scope.dpLname,
Collection: {
"InputList": [{
"FieldName": "dpFname",
"DisplayName": "First Name",
"Required": "1",
"AllowEdit": "1",
"TabOrder": "1",
"InputType": "TEXTBOX",
"Style": "",
"Validate": "",
"InputMask": "",
"Options": [],
"Value": $scope.dpFname
}, {
"FieldName": "dpLname",
"DisplayName": "Last Name",
"Required": "1",
"AllowEdit": "1",
"TabOrder": "3",
"InputType": "TEXTBOX",
"Style": "",
"Validate": "",
"InputMask": "",
"Options": [],
"Value": $scope.dpLname
}, {
"FieldName": "dpMname",
"DisplayName": "Middle Name",
"Required": "0",
"AllowEdit": "1",
"TabOrder": "2",
"InputType": "TEXTBOX",
"Style": "",
"Validate": "",
"InputMask": "",
"Options": [],
"Value": $scope.dpMname
}
]
}
});
// Clear form fields
$scope.dpFname = '';
$scope.dpLname = '';
$scope.dpMname = '';
};
}
輝煌,謝謝! – Nick