Javascript 使用动态ng模态数据提交角度表单
最初我是angular的新手。我提交了一个简单的表单提交,其中有许多输入字段将来自一个对象。我的问题是我无法在单击按钮时收集修改后的表单数据jsonJavascript 使用动态ng模态数据提交角度表单,javascript,angularjs,Javascript,Angularjs,最初我是angular的新手。我提交了一个简单的表单提交,其中有许多输入字段将来自一个对象。我的问题是我无法在单击按钮时收集修改后的表单数据json <form id="fmsubmit" role="form"> <div class="form-group" ng-repeat="(key, value) in showCase.person"> <label for="{{key}}">{{key}}</label>
<form id="fmsubmit" role="form">
<div class="form-group" ng-repeat="(key, value) in showCase.person">
<label for="{{key}}">{{key}}</label>
<input type="text" ng-disabled="key=='rowId'" class="form-control" id="{{key}}" placeholder="{{key}}" name="{{key}}" value={{value}} ng-modal="row[value]"/>
</div>
<button type="submit" ng-click="showCase.submitData(row)" class="btn btn-default">Submit</button>
</form>
我认为这一行没有定义。而且它也不适用于范围。对此,必须使用$scope.$apply()。以及为什么要使用动态ng模型?使用角度静态方法和模型,您可以管理任何类型的表单。还可以尝试一些指令 两件事:ng模型中的输入错误,行未定义
老实说,我不完全确定你想做什么。我假设您希望基于对象结构生成表单,并且在表单中的更改得到对象更新后生成表单。如果你想让我描述这个场景,那么你可以在这里拉小提琴:
编辑:
如果您希望有一个新变量“row”负责存储人员数据,那么这里有一个示例:
它的打字错误是
ng model
而不是ng model
谢谢。。我更改了“ng模型”,然后它也不工作了。行定义在哪里?也许可以尝试ng repeat=“showCase.person中的行”
$scope.submitData = function(person){
console.log(person);
}
<form id="fmsubmit" role="form">
<div class="form-group" ng-repeat="(key, value) in showCase.person">
<label for="{{key}}">{{key}}</label>
<input type="text" class="form-control" id="{{key}}" ng-disabled="key=='rowId'" placeholder="{{key}}" name="{{key}}" ng-model="showCase.person[key]" />
</div>
<button type="submit" ng-click="showCase.submitData(showCase.person)" class="btn btn-default">Submit</button>
</form>
function TestCtrl($scope) {
$scope.showCase = {};
$scope.showCase.person = {
"id": 2,
"project": "wewe2012",
"date": "2013-02-26",
"description": "ewew",
"eet_no": "ewew",
};
$scope.showCase.submitData = function (person) {
console.log(person);
alert(JSON.stringify(person));
};
}
<form id="fmsubmit" role="form" ng-init="row={}">
<div class="form-group" ng-repeat="(key, value) in showCase.person" ng-init="row[key]=value">
<label for="{{key}}">{{key}}</label>
<input type="text" class="form-control" id="{{key}}" ng-disabled="key=='rowId'" placeholder="{{key}}" name="{{key}}" ng-model="row[key]" />
</div>
<button type="submit" ng-click="showCase.submitData(row)" class="btn btn-default">Submit</button>
</form>
function TestCtrl($scope) {
$scope.showCase = {};
$scope.showCase.person = {
"id": 2,
"project": "wewe2012",
"date": "2013-02-26",
"description": "ewew",
"eet_no": "ewew",
};
$scope.showCase.submitData = function (person) {
console.log(person);
alert(JSON.stringify(person));
};
}