1

这可能不是关于 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>&nbsp;&nbsp;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>&nbsp;&nbsp;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: ""

这是我希望在我的 rest api 帖子中提供的内容:

Object {entries: Array[1]}
 entries: Array[1]
  0: Object
   answer: Array[1]
    0: Object
     id: "a"
     text: "Homer Simpson"

请注意 entry.answer 属性之间的区别,即我坚持的地方。T__T。

4

1 回答 1

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>
于 2013-09-25T07:23:50.423 回答