【发布时间】:2016-06-27 02:18:10
【问题描述】:
我正在尝试使用 ng-repeat 中的重复变量作为 ng-model 的一部分,该变量被传递给控制器以插入 MongoDB。
在下面的html中,我使用了
<input... ng-model="tablesList.person.lastName />
我真的想要每个列字段的输入
<input... ng-model="tablesList.person.{{column.field}} />
但是,这会产生错误。也没有
<input... ng-model="tablesList.person.column.field />
将 column.field 作为字符串。
任何想法如何让它发挥作用?我尝试使用 getter/setter 函数,但不确定如何正确执行此操作,或者是否有必要。
HMTL:
<form name="newTableRowForm" novalidate ng-cloak>
<td ng-repeat="column in tablesList.ammiTables">
<md-input-container flex class="md-block">
<input type="text" ng-model="tablesList.person.lastName" />
</md-input-container>
</td>
<td>
<md-button ng-click="tablesList.submit()" class="md-primary" ng-disabled="newTableRowForm.$invalid" aria-label="send">
Submit <md-icon md-svg-icon="content:ic_send_24px"></md-icon>
</md-button>
</td>
</tr>
</form>
提交部分控制器:
submit() {
this.person.owner = Meteor.user()._id;
Persons.insert(this.person);
if(this.done) {
this.done();
}
this.reset();
}
【问题讨论】: