简体   繁体   English

更新倍数值并使用AngularJS和laravel显示

[英]Update the multiple value and display using AngularJS and laravel

[{"user_id":78936,"social_id":null,"type":2,"name":"Get Raj","first_name":"Get","last_name":"Raj","email":"test1@yopmail.com"},

{"user_id":78937,"social_id":null,"type":2,"name":"James thomas","first_name":"James","last_name":"thomas","email":"jamesthoms@yopmail.com"}] 

<div ng-repeat="user in profiles">
    <div class="col-sm-5 col-ie-5">
    <input
      type="text"
      name="entry_{{user.user_id}}"
      ng-model="update.entry"
      ng-change="save(user, update)"
      >
    </div>

    <div class="col-sm-5 col-ie-5">
    <input
      type="text"
      name="info_{{user.user_id}}"
      ng-model="update.info"
      ng-change="save(user, update)"
      >
    </div>

    <div class="col-sm-5 col-ie-5">
    <input
      type="text"
      name="textual_{{user.user_id}}"
      ng-model="update.textual"
      ng-change="save(user, update)"
      >
    </div>          
</div>


function makeOrderItemUrl(user_id, order_id){
       return 'v1/update/' + user_id + '/order_id/' + order_id;
    }

$scope.save = function (person, update) {


     var person = person;
     var order = null,
     matchCount = 0;

        for (var i = 0; i < $scope.order.items.length; i++) {
                if ($scope.order.items[i].user_id == person.user_id) {
                  order = $scope.order.items[i];
                  matchCount++;
                }
              }

      if(order){
          $http.post(makeOrderItemUrl(person.user_id, order.order_id), update)
          .success(function(res){
            $scope.update = res.data;
          }).error(function () {
            notify.message('There was an issue saving your changes, please try again later.');
          });  
      }

    };

Since we have two users so we will get twice input fields ie ng-model="update.entry" two times then whenever I type in the first textbox it get reflected the same value in the second textbox as well because of the same model they are using how can I set different models and value to be saved into the database and display respectively. 由于我们有两个用户,因此我们将获得两次输入字段,即ng-model =“ update.entry”两次,然后每当我在第一个文本框中键入内容时,由于相同的模型,它们也会在第二个文本框中反映相同的值使用如何设置不同的模型和值以分别保存到数据库和显示。

Laravel 

$orderItem =  OrderItem::firstOrNew([
                    'user_id' => $user_id,
                    'order_id' => $order_id
                    ]); 

if($orderItem->exists){
            $orderItem->entry = Input::get('entry');    
            $orderItem->save();
        }

//This is working fine but it's hard to display. //这很好,但是很难显示。

Make update a deeper object where the user id's are used as first level keys 使update成为更深层的对象,其中将用户标识用作第一级密钥

<input
      type="text"
      name="entry_{{user.user_id}}"
      ng-model="update[user.user_id].entry"
      ng-change="save(user, update[user.user_id])"
      >

Then $scope.update would look like: 然后$scope.update看起来像:

{
  id1: {
    textual: '...',
    entry: '...',
    info: '...'
  },
  id2: {
    textual: '...',
    entry: '...',
    info: '...'
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM