'Invalid left-hand side in assignment' 使用 NOT(!) 运算符时出错

'Invalid left-hand side in assignment' error when using the NOT(!) operator

我正在使用这个功能:

$scope.myFunction = function(indexParent, childrenLength) {

    // close all inner accordion tabs
     for(i=0; i < childrenLength; i++) {
       !$scope.lettersandnumbers[indexParent].things[i].open = $scope.lettersandnumbers[indexParent].things[i].open;
     }

    // toggle parent tab
    $scope.lettersandnumbers[indexParent].open = !$scope.lettersandnumbers[indexParent].open;

 }

此处:<button ng-click="myFunction(0, 3)">Toggle a</button> 但是 'close all inner accordion tabs' 部分给我 Invalid left-hand side in assignment 错误。我怎样才能修改代码以使其工作?

https://plnkr.co/edit/TlKhBZer1wYMW0XXBcqO?p=preview

非常感谢

更新

回答有一些修改:https://plnkr.co/edit/aMD5rGxpe48lziTb6xPk?p=preview

您的代码应该类似于

$scope.myFunction = function(indexParent, childrenLength) {

    // close all inner accordion tabs
     for(i=0; i < childrenLength; i++) {
       $scope.lettersandnumbers[indexParent].things[i].open = !$scope.lettersandnumbers[indexParent].things[i].open;
     }

    // toggle parent tab
    $scope.lettersandnumbers[indexParent].open = !$scope.lettersandnumbers[indexParent].open;

 }

! 在作业的左侧

编辑:

你不能在左侧使用 ! 的证明:

var a = true;
console.log(a);
!a = a;

编辑 2:

$scope.myFunction = function(indexParent, childrenLength) {

  // First close the outer tab
   $scope.lettersandnumbers[indexParent].open = !$scope.lettersandnumbers[indexParent].open;

  // Close all inner tabs if the outer tab is closed
  for(i=0; i < childrenLength; i++) {
    $scope.lettersandnumbers[indexParent].things[i].open = !$scope.lettersandnumbers[indexParent].open ? false : $scope.lettersandnumbers[indexParent].things[i].open;
  }
}

我在这里使用 ternary operator 来确定是否应该关闭内部标签。

我在你的代码中看到 myFunction 只在一个按钮上被调用,你应该找到你点击外部手风琴时让它工作的方法