在我的休息 api 调用中重组我对供应的响应

Restructuring my response to supply in my rest api call

本文关键字:响应 重组 我的 api 调用      更新时间:2023-09-26
这可能

不是关于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="answerswer in q.answer">
        <div>
            <select id="city" ng-model="answerswer.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 -->

当我提交我的表单并控制台.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"

请注意 entryries.answer 属性之间的区别,即我卡在的地方。T__T。

我认为

 <select id="city" ng-model="answerswer.id" ng-options="c.id for c in q.options">
            </select>

应该是

 <select id="city" ng-model="answerswer.id" ng-options="c.id as c.id for c in q.options">
            </select>