这可能不是关于angularjs的问题,但这让我很难解决。所以我在这里问也许有人可以帮助我。我的问题是构建我提交表单时获得的正确的发布值
这是我的观点。
<div ng-repeat="q in entries">
<h4>Question # {{$index+1}}</h4>
<div>
<labelfor="">Options: </label>
<a ng-click="addOption($event, $index)">
<i class="icon-plus-sign icon-large"></i> Add option
</a><br /><br />
<div ng-repeat="opt in q.options">
<label><span>{{opt.id}}.</span></label>
<input type="text" ng-model="opt.text" placeholder="Add new possible answer here.">
<a ng-click="q.options.splice($index,1)"><i class="icon-remove-sign icon-large"></i></a>
</div>
</div>
<div>
<label for="required_credit">Answer: </label>
<a ng-click="addAnswer($event, $index)">
<i class="icon-plus-sign icon-large"></i> Add answer
</a><br /><br />
<!-- This is the part where my response got wrong -->
<div ng-repeat="answer in q.answer">
<div>
<select id="city" ng-model="answer.id" ng-options="c.id for c in q.options">
</select>
<a ng-click="q.answer.splice($index,1)"><i class="icon-remove-sign icon-large"></i></a>
</div>
</div>
</div>
<!-- end -->
当我提交我的表单和console.log postData时,这就是我得到的:
Object {entries: Array[1]}
entries: Array[1]
0: Object
answer: Array[1]
0: Object
id: Object
id: ""
text: ""
text: ""
这是我希望在我的休息api帖子中提供的内容:
Object {entries: Array[1]}
entries: Array[1]
0: Object
answer: Array[1]
0: Object
id: "a"
text: "Homer Simpson"
注意entries.answer属性之间的区别,我坚持的地方。 T__T。
答案 0 :(得分:1)
我认为
<select id="city" ng-model="answer.id" ng-options="c.id for c in q.options">
</select>
应该是
<select id="city" ng-model="answer.id" ng-options="c.id as c.id for c in q.options">
</select>