我正在尝试从 JSON 创建一个表单。每个输入都用 JSON 描述,我遍历它们并创建输入。我现在想在输入中放入一些数据,并保存这些数据。我尝试使用哈希,其中键是数据字段名称,值是用户输入的值。
这是我的代码:
<form action="#" method="POST" class="form-horizontal" id="form2" onsubmit="return false;">
<fieldset id="fieldset1">
<div class="control-group" data-ng-repeat="item in last_admin.templates" data-ng-show="item.name != 'Default Order'">
{{create_new_record(item)}}
<label class="control-label">{{item.name}}:</label>
<div class="span3 controls" data-ng-switch on="item.type">
<div data-ng-switch-when="LIST">
<select data-ng-model="new_record[item.name]" data-ng-options="option.value as option.name for option in create_options_array(last_admin.templates, item.name)" class="span3" ></select>
</div>
<div data-ng-switch-when="STRING">
<input class="span3" type="text" novalidate="" data-ng-model="new_record[item.name]" />
</div>
</div>
</div>
<div class="clearfix" style="margin-bottom: 20px;"></div>
<div class="">
<button class="btn btn-primary pull-right" data-ng-click="new_data(); $parent.create_form = false;">Save</button>
<ul class="nav nav-pills pull-right" style="margin-right: 10px; margin-bottom: 0px;">
<li><a href="javascript:void(0);" data-ng-click="$parent.create_form = false">Cancel</a></li>
</ul>
</div>
<div class="clearfix"></div>
</fieldset>
</form>
控制器:
$scope.new_record = {};
$scope.create_new_record = function(template){
$scope.new_record[template.name] = "dd";
}
问题是我无法在输入中输入任何内容。