Javascript 在restapi调用中重新构造对supply的响应

Javascript 在restapi调用中重新构造对supply的响应,javascript,angularjs,Javascript,Angularjs,这可能不是angularjs的问题,但这让我很难解决。所以我在这里问,也许有人能帮助我。我的问题是如何构造提交表单时得到的正确的发布值 这是我的看法 <div ng-repeat="q in entries"> <h4>Question # {{$index+1}}</h4> <div> <labelfor="">Options: </label> <a ng-click="addOption($ev

这可能不是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 -->
这就是我希望在rest api帖子中提供的内容:

Object {entries: Array[1]}
 entries: Array[1]
  0: Object
   answer: Array[1]
    0: Object
     id: "a"
     text: "Homer Simpson"
请注意entries.answer属性之间的差异,我一直停留在这里。我想

 <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>

我想

 <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>


我读了两遍,仍然不知道你的问题是什么。难怪你很难解决这个问题。我读了两遍,仍然不知道你的问题是什么。难怪您在修复此问题时遇到困难。给了我一个错误:错误:应该是“选择(作为标签)”形式的Ngoption?对于(key,)?_value_uuin collection'但获得了“q.options中c.id的c.id”。@WonderingCoder我已经修复了表达式,请检查。我能够获得我的postData的正确结构,但我只获得了id值,我还需要添加“c.text”的值并将其传递给我的控制器。如果我更改了ng options=“c.text..”则我将只获取文本,如何同时获取c对象的id和文本?使用之前的表达式,您将获取文本和id,但这会导致发布数据出现问题。您可以将所选值放入其他变量中,然后手动将answer.id分配给所选元素的it。对不起,我对前面的响应进行了硬编码,以使其能够理解我的情况。但从一开始,我只能指定一个值id或text,而不能同时指定两者。你的意思是我可以放置一个隐藏字段并在那里分配文本或id吗?给了我一个错误:错误:应该是“选择(作为标签)”形式的ngOptions?对于(key,)?_value_uuin collection'但获得了“q.options中c.id的c.id”。@WonderingCoder我已经修复了表达式,请检查。我能够获得我的postData的正确结构,但我只获得了id值,我还需要添加“c.text”的值并将其传递给我的控制器。如果我更改了ng options=“c.text..”则我将只获取文本,如何同时获取c对象的id和文本?使用之前的表达式,您将获取文本和id,但这会导致发布数据出现问题。您可以将所选值放入其他变量中,然后手动将answer.id分配给所选元素的it。对不起,我对前面的响应进行了硬编码,以使其能够理解我的情况。但从一开始,我只能指定一个值id或text,而不能同时指定两者。你的意思是我可以把一个隐藏的字段和分配的文本或id那里?