Javascript 如何以数组形式提交下拉输入字段
我有一个javascript对象的嵌套列表Javascript 如何以数组形式提交下拉输入字段,javascript,angularjs,Javascript,Angularjs,我有一个javascript对象的嵌套列表Templates.schema 每页将有许多部分,我必须跟踪它们(通过索引) 如何确保在提交表单时,addPage()函数通过input ng model=“pageAdder.page.section <form ng-model="pageAdder" ng-submit="addPage()"> <label for="page.name">PAGE</label> <input type
Templates.schema
每页将有许多部分,我必须跟踪它们(通过索引)
如何确保在提交表单时,addPage()
函数通过input ng model=“pageAdder.page.section
<form ng-model="pageAdder" ng-submit="addPage()">
<label for="page.name">PAGE</label>
<input type="text" ng-model="pageAdder.page.name">
<br>
<hr>
<label for="page.name">Section</label>
<select id="s1" ng-model="pageAdder.page.section" ng-options="item as item.type for item in items"></select>
<br>
<hr>
<input class="btn btn-primary" type="submit" value="add Page">
</form>
控制器
angular.module("ang6App")
.controller("MainCtrl", function ($scope) {
})
.controller("templatesCtrl", function ($scope, Templates) {
$scope.template = Templates;
$scope.addPage = function() {
$scope.template.schema.push($scope.pageAdder);
};
$scope.items = [
{ id: 1, type: 'foo' },
{ id: 2, type: 'bar' },
{ id: 3, type: 'blah' }];
$scope.pageAdder = {
};
//end of templates
});
将默认值添加到$scope.pageAdder
而且效果很好:
angular.module("ang6App")
.controller("MainCtrl", function ($scope) {
})
.controller("templatesCtrl", function ($scope, Templates) {
$scope.template = Templates;
$scope.addPage = function() {
$scope.template.schema.push($scope.pageAdder);
};
$scope.items = [
{ id: 1, type: 'foo' },
{ id: 2, type: 'bar' },
{ id: 3, type: 'blah' }];
$scope.pageAdder = {
};
//end of templates
});
$scope.pageAdder = {
"page": {
"name": null,
"section": [{
"id": null,
"type": null
}]
}