Javascript 组合作用域后,字段在角度中未正确重复
我只是使用以下方法组合了模型的作用域: 但是现在它在Javascript 组合作用域后,字段在角度中未正确重复,javascript,angularjs,angularjs-ng-repeat,Javascript,Angularjs,Angularjs Ng Repeat,我只是使用以下方法组合了模型的作用域: 但是现在它在字段对象之外创建了一个单独的字段对象,这是它以前没有做过的 HTML <li order="" class="field-dropped text" ng-repeat="field in theForm.fields" ng-switch="theForm.field.type"> <div class="field-actions"><i class="icon-edit"></i>
字段
对象之外创建了一个单独的字段
对象,这是它以前没有做过的
HTML
<li order="" class="field-dropped text" ng-repeat="field in theForm.fields" ng-switch="theForm.field.type">
<div class="field-actions"><i class="icon-edit"></i> <i class="icon-move"></i> <i class="icon-remove"></i>
</div>
<h4>{{theForm.field.label}}</h4>
<em class="field-desc">{{theForm.field.desc}}</em>
<!-- type: text -->
<input ng-switch-when="text" type="text" placeholder="" disabled class="span6">
<!-- type: para -->
<textarea ng-switch-when="para" type="text" placeholder="" disabled class="span6"></textarea>
<!-- type: drop -->
<select ng-switch-when="drop" placeholder="" disabled class="span6"></select>
<div class="field-options well">
<label>Field Title</label>
<input type="text" placeholder="Field Label" class="span8" ng-model="theForm.field.label">
<label>Field Description</label>
<textarea class="description span8" type="text" placeholder="Field Description" ng-model="theForm.field.desc"></textarea>
<label class="checkbox">
<input type="checkbox" value="" ng-model="theForm.field.req">Required?</label>
<!-- type: drop -->
<label ng-switch-when="drop" class="checkbox">
<input type="checkbox" value="" ng-model="theForm.field.dropOptionsMul">Allow Multiple Choices?</label>
<label ng-switch-when="drop">Options</label>
<em ng-switch-when="drop">Enter a new option on each line.</em>
<textarea ng-switch-when="drop" class="span6" type="text" placeholder="Options" ng-list=" " ng-trim="false" ng-model="theForm.field.dropOptions"></textarea>
</div>
<input class="sortOrder" id="" name="" value="" type="hidden">
</li>
JSON输出
{
"formTitle": "",
"formDesc": "",
"fields": [],
"field": {
"label": "The actual field title",
"desc": "The actual field description"
}
}
字段
成为表单字段中每个对象的“快捷方式”
因此,在ng repeat
中,您可以通过键入来调用它
就像说
for (i = 0; i < theForm.fields.length; i++) {
var field = theForm.fields[0];
// from now on you access it by field
field.type = 'My Type';
}
for(i=0;i
AngularJS将字段添加到表单
,因为ng模型
指令引用了表单字段.xxx
;它应该是xxx
。Angular通过ng repeat
知道您指的是什么。这根本不起作用。不确定我是否理解您在这里所说的内容字段是不同的单独对象,它不是表单的一部分。你像以前那样称呼它。只需打字。你有例子吗?不知道如何在ng repeat=。。。块,基本上在该li中,不要使用表单字段。
,只使用字段
ng-repeat="field in theForm.fields"
for (i = 0; i < theForm.fields.length; i++) {
var field = theForm.fields[0];
// from now on you access it by field
field.type = 'My Type';
}