2016-04-03 40 views
2

Belirli bir anahtarla json'u güncellemek için en iyi uygulama nedir. Benim durumumda, 'cevapsız' dan 'cevaplandı' kısmına geri bildirim güncellemek istiyorum. AngularJS: JSON'u belirli bir anahtarla güncelleyin

<div class="parent" ng-repeat="customer in customers"> 
    <h2>{{customer.id}}</h2> 
    <p>{{customer.question}}</p> 
    <h4 ng-show="{{customer.is_answered}}">Answered</h4> 
    <h4 ng-show="!{{customer.is_answered}}">Not Answered</h4> 
    <button ng-show="!{{customer.is_answered}}" ng-click="showModal()">Reply</button> 
</div> 

i cevap butonuna tıklayın

ardından yanıta benim müşteri şikayetlerini bazı girdilerin ile modal görünür:

[ 
    { 
    "id": "34", 
    "mac_address": "cd:9e:17:64:1b:42", 
    "question": "Help me", 
    "time": "2016-03-16 16:22:08", 
    "is_answered": false 
    } 
] 

[ 
     { 
     "id": "34", 
     "mac_address": "cd:9e:17:64:1b:42", 
     "question": "Help me", 
     "time": "2016-03-16 16:25:29", 
     "is_answered": true 
     } 
    ] 

bazı liste benim müşteri istek vardır.

<div id="modal"> 
<textarea placeholder=""response></textarea> 
<button ng-click="submit()">Reply</button> 
</div> 

Geri bildirim kimliğine dayalı olarak güncellemek istiyorum ve yine nasıl yapılacağını en iyi uygulama nedir?

+0

ederiz? – JordanHendrix

+0

Şahsen lodash findIndex öğesini kullanarak öğeyi kimliğine göre getirip güncelleştirmeyi gerçekleştirir - https://lodash.com/docs#findIndex – dmoo

+0

Kısa süre önce bu bağlantıyı buldu: [link] (http://stackoverflow.com/questions/ 30917576/angularjs-open-modal-ile-spesifik-data-from-array), benzer konu – artemist

cevap

1

Müşteri nesnesini showModal çağrısıyla iletebilirsiniz.

<div class="parent" ng-repeat="customer in customers"> 
    <h2>{{customer.id}}</h2> 
    ... 
    <button ng-show="!{{customer.is_answered}}" ng-click="showModal(customer)">Reply</button> 
</div> 

Denetleyicinizin içinde, bunu müşteriye aktarın. Modal kapandıktan sonra, söz konusu müşterinin is_answered özelliğini güncelleyin.

$scope.showModal = function (customer) { 
    var selected_customer = customer; 

    var modalInstance = $uibModal.open({ 
    templateUrl: 'myModalContent.html', 
    controller: 'ModalInstanceCtrl', 
    customer: customer 
    }); 

    modalInstance.result.then(function() { 
    selected_customer.is_answered = true; 
    } 
}; 
+0

hala kafa karıştırıcıyım..ok, sorularım basitleştirilmiştir, sorularımın içinde nasıl görüntülendiğimi anlatıyorum. Aslında ben özel id ile $ mdDialog kullanıyorum. – artemist

0

Çözümüm bulundu, Pass input value to $mdDialog. Bence

vm.showModal = function(e, message) { 

     $mdDialog.show({ 
     clickOutsideToClose:true, 
     // locals:{ name: 'Bob'}, 
     controller: function ($mdDialog) { 
      var vm = this; 
      vm.message = {}; 
      vm.message = message; 

      $scope.hide = function() { 
      $mdDialog.hide(); 
      }; 
      $scope.cancel = function() { 
      $mdDialog.cancel(); 
      }; 
     }, 
     controllerAs: 'modal', 
     templateUrl: 'feedbackForm.html', 
     parent: angular.element(document.body), 
     targetEvent: e, 
     }); 
    }; 

:

<h5 style="">{{modal.message.id}}</h5> 

siz biz denetleyici kodunu görebilirsiniz

İlgili konular