我有一个表单,旨在让用户编辑一些信息
我的问题在于<input class="form-control" type="text" ng-repeat="info in item.Question" ng-model="info"/>
。当我单击保存按钮时,日志(下面复制的示例)告诉我它没有更新模型。谁能明白为什么?
我读了一些其他问题,ng-model需要一个object.property值,但我不知道如何在这里应用
<div class="panel panel-primary" ng-show="item.edit">
<div class="panel-heading">
<h3 class="panel-title">
<form class="form-group form-inline">
<input class="form-control" type="text" ng-model="item.Name" />
<span class="badge pull-right">₤<input class="form-control" type="number" step="any" ng-model="item.Price" /></span>
</form>
</h3>
</div>
<div class="panel-body">
<input class="form-control" type="text" ng-model="item.Desc" />
<hr>
<div class="col-md-11">
<input class="form-control" type="text" ng-repeat="info in item.Question" ng-model="info"/>
</div>
<div class="col-md-1">
<a href="" ng-click="cat.newQuestion(item)" class="btn btn-success"><span class="glyphicon glyphicon-plus"></span></a>
</div>
</div>
<div class="panel-footer">
<div class="btn-group">
<a href="" ng-click="cat.change(item)" class="btn btn-success">Save</a>
<a href="" ng-click="item.edit = false" class="btn btn-primary">Cancel</a>
<a href="" ng-click="cat.deleteItem(item)" class="btn btn-danger">Delete</a>
</div>
</div>
</div>
来自change()
函数的日志示例:
app.js:39 Object {ID: "10", Name: "New User", Price: 0, Desc: "Create a new user for the Quarriers network", CatID: "3"…}$$hashKey: "object:50"CatID: "3"Desc: "Create a new user for the Quarriers network"ID: "10"Name: "New User"Price: 0Question: "username,"edit: true
app.js:40 stringing
app.js:46 Object {ID: "10", Name: "New User", Price: 0, Desc: "Create a new user for the Quarriers network", CatID: "3"…}$$hashKey: "object:50"CatID: "3"Desc: "Create a new user for the Quarriers network"ID: "10"Name: "New User"Price: 0Question: "username,"edit: true__proto__: Object
答案 0 :(得分:1)
如果您不想将Question
更改为具有属性的对象,可以使用以下内容:
<input ng-repeat="info in item.Question track by $index" ng-model="item.Question[$index]"/>