如何使函数将属性值从 FALSE 设置为 TRUE



我正在使用角度做这个项目,其中我有一个带有属性和值的 JSON 对象的集合。所有对象都有一个属性,其值设置为 FALSE

  myApp.controller('MyController', function($scope){
    $scope.customers = [
  {'name':'Ali','link':'https://facebook.com','done':false, 'call': 0},
  {'name':'khaled','link':'https://google.com','done':false, 'call': 0},
  {'name':'Salim','link':'https://technet.com','done':false, 'call': 0}
  ]

HTML 页面中的按钮应该调用函数 upCall(customer)

   <div ng-repeat="customer in customers | orderBy: '-call'">
      <button ng-click="upCall(customer)" class="glyphicon glyphicon-earphone"></button>

该按钮应该调用下面的upCall(customer)函数

$scope.upCall = function(customer) {
  return customer.done === true;
}

但是,在调试浏览器时,该按钮永远不会将对象的属性设置为 TRUE

是我应该担心的语法

尝试this选项

<div ng-repeat="customer in customers | orderBy: '-call'">
      <button ng-click="upCall(**this**)" class="glyphicon glyphicon-earphone"></button>

$scope.upCall = function(customerContext) {
  **customerContext.done = true;**
  return customerContext;
}

return customer.done === true;此语句检查customer.done是否完全等于 true .这将返回false .you 没有改变customer.done .so

return customer.done = true;

最新更新