gpt4 book ai didi

javascript - AngularJS:使用特定键以模式更新 JSON

转载 作者:行者123 更新时间:2023-11-30 00:11:19 25 4
gpt4 key购买 nike

使用特定键更新 View 中的 json 的最佳做法是什么。就我而言,我想将反馈从“未回答”更新为“已回答”。

[
{
"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
}
]

有一些我的客户反馈列表:

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

当我点击回复按钮时,会出现带有一些输入的模态以回复我的客户投诉。

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

我想根据反馈 ID 进行更新,再说一遍,最佳做法是什么?

最佳答案

您可以通过 showModal 调用传递客户对象。

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

在您的 Controller 中,保存传入的客户。模式关闭后,更新该客户的 is_answered 属性。

 $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;
}
};

关于javascript - AngularJS:使用特定键以模式更新 JSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36380629/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com