是否可以仅使用一个功能和一个按钮使用 angularjs 更新多个 json object?

Is it possible to update multiple json object using just one function and one button using angularjs?

她是 HTML 代码

<ion-view view-title="Reviewer Title">
<ion-content>
  <div class="content no-header">
    <ion-nav-bar class="bar-assertive-900" align-title="left">
    <ion-nav-buttons side="left">
        <button class="button button-icon button-clear ion-android-arrow-back" ui-sref="app.reviewers"> </button>
    </ion-nav-buttons>

    <ion-nav-buttons side="right">
       <button class="button button-icon button-clear ion-android-done-all" 
       ng-click="edtRv.edit(edtRv.e[0].id,qs_id,chs_id, rv_object,qs_object,chs_object)"> </button>
       <button class="button button-icon button-clear ion-trash-b"> </button> 
    </ion-nav-buttons>
  </ion-nav-bar>

    <br> <br> <br>

  <div class="blk"> 
  <input type="text" value="{{edtRv.e[0].rev_name}}" >  
  </div>

  <div class="button-bar">
    <a class="button button-outline button-assertive" ng-click="showCard()"> show all</a>
    <a class="button button-outline button-assertive" ng-click="hideCard()"> hide all</a>
  </div>

  <form ng-repeat="edit in edtRv.e">
    <ion-item ng-if="edit.question_type_id == 1">
     <ion-checkbox ng-if=""> </ion-checkbox> 
  <div class="list list-inset">
    <div>
        Rv id{{edit.id}}
        Qstn id{{edit.id1}}
        Chs id{{edit.id2}}
        <label class="item item-input">
        <b><span class="input-label item-num"> {{$index+1}}.) </span> </b>
          <input type="text" ng-value="edit.question">
        </label>
    </div>

    <div id="startCard" ng-show="showstartCard">
        <label class="item item-input">
        <b><span class="input-label item-num"> Answer: </span> </b>
          <input type="text" ng-value="edit.answer">
        </label>
    </div>
  </div>
  </ion-item>

  <ion-item  ng-if="edit.question_type_id == 2">
     <ion-checkbox ng-if=""> </ion-checkbox>
  <div class="list list-inset">
    <div>
    Rv id{{edit.id}}
        Qstn id{{edit.id1}}
        Chs id{{edit.id2}}
      <label class="item item-input">
      <b><span class="input-label item-num"> {{$index+1}}.) </span> </b>
        <input type="text" ng-value="edit.question">
      </label>
    </div>

    <div id="startCard" ng-show="showstartCard">
      <label class="item item-input">
      <b><span class="input-label item-num"> Answer: </span></b>
        <input type="text" ng-value="edit.answer">
      </label>
      <label class="item item-input">
      <b><span class="input-label item-num"> choice 1: </span></b>
        <input type="text" ng-value="edit.choice_1">
      </label>
      <label class="item item-input">
      <b><span class="input-label item-num"> choice 2: </span></b>
        <input type="text" ng-value="edit.choice_2">
      </label>
      <label class="item item-input">
      <b><span class="input-label item-num"> choice 3: </span></b>
        <input type="text" ng-value="edit.choice_3">
      </label>
    </div>
  </div>
  </ion-item>
</form>


</ion-content>

我想做的是更新审阅者的标题,问题和选择只用一个功能或 view.I 中的一个按钮不希望每个项目都有按钮所以有办法怎么做?谢谢 :D

这是服务文件

service.update = function (rv_id,qs_id,chs_id, rv_object,qs_object,chs_object) {
        // return $http.put(getUrlForId(id), object);

        // for updating rev object
        return $http.put(getRevUrlForId(rv_id), rv_object)
            .then(function (result) {
                console.log(result.data);
            });
        // for updating qstn object
        return $http.put(getQsUrlForId(qs_id), qs_object)
            .then(function (result) {
                    console.log(result.data);
                });
        // for updating chs object
        return $http.put(getChoicesUrlForId(chs_id), chs_object)
            .then(function (result) {
                console.log(result.data);
            });
    };

这是控制器

.controller('EditRevCtrl', function($scope, $timeout, $stateParams, $ionicPopup, ionicMaterialInk, ItemsModel, Backand) { var edtRv = 这个;

edtRv.e = ItemsModel.getcontForEdit(); // use for getting reviewers info

function edit (rv_id,qs_id,chs_id, rv_object,qs_object,chs_object) {
  ItemsModel.update(rv_id,qs_id,chs_id, rv_object,qs_object,chs_object);
}
})

当然可以!

首先,您应该将 $q 注入到您的服务中,因为我们将在下面使用它。 使用 Q 你可以传递一系列要解决的承诺。

service.update = function (rv_id,qs_id,chs_id, rv_object,qs_object,chs_object) {
    return $q.all([
        $http.put(getUrlForId(id), object),
        $http.put(getRevUrlForId(rv_id), rv_object),
        $http.put(getQsUrlForId(qs_id), qs_object),
        $http.put(getChoicesUrlForId(chs_id), chs_object),
    ]).then(function(results) {
        var UrlForId = results[0];
        var RevUrlForId = results[1];
        var QsUrlForId= results[2];
        var ChoicesUrlForId= results[3];

        return results;
    })
};