Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/457.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 获取ng repeat中ng repeat外的收音机索引_Javascript_Angularjs - Fatal编程技术网

Javascript 获取ng repeat中ng repeat外的收音机索引

Javascript 获取ng repeat中ng repeat外的收音机索引,javascript,angularjs,Javascript,Angularjs,我正试图使用选定的收音机作为其数组中索引的引用,以便可以在其子数组中添加更多子项(使用选定的收音机) 这就是我所拥有的: <div class="fakeTableRow" ng-repeat="parent in listTable"> <div class="strcutionLeft"></div> <!-- parent levels --> <div class="strcutionCRight saInstrcut

我正试图使用选定的收音机作为其数组中索引的引用,以便可以在其子数组中添加更多子项(使用选定的收音机)

这就是我所拥有的:

<div class="fakeTableRow"  ng-repeat="parent in listTable">
  <div class="strcutionLeft"></div>
  <!-- parent levels -->
  <div  class="strcutionCRight saInstrcutionTitle"><div class="parentSub1"> <input type="radio" name="levelCheckDat" ng-model="levelChecker" value="{{$index}}">{{parent.name}}</div></div>
</div>   
我的假设是,收音机存储在它们自己的作用域中,但是如果我只是
log($scope.levelChecker)
它返回时没有定义,因此我认为我认为这是错误的,我似乎无法弄清楚怎么做

为了清楚起见,我只是想用levelChecker的模型计算出所选收音机的索引(在ng repeat中)。谢谢你的阅读


编辑:我将按钮的值交换到{$index}},看看是否可以通过调用作用域来提取值

尝试将父函数传递给函数,然后传递$scope.levelChecker.indexOf(parent);我认为我的问题的一部分是,如果我使用console.log($scope.levelChecker),它将返回未定义。我认为它建立了自己的范围,但我认为我在细节上有点错误,谢谢!我会在单选按钮上单击ng,该按钮将调用您作用域中的函数。将$index作为参数传递给该函数。然后在$scope中获得所选单选按钮的索引。那会有帮助吗?我会试一试的!谢谢@spike!再仔细想想,我意识到这听起来有点像你在想jQuery。考虑修改模型,而不是添加基于单选按钮索引的行为。您的型号中是否已有子收音机所需的信息?然后通过将某些属性设置为“true”来标记它,以便将“parent”传递到方法中。如果你没有,在你的作用域中写一个方法,传入“parent”并使用它的id从一些API获取更多信息。这有意义吗?
$scope.submitNewSub = function(){
  //get index of radio
  console.log($scope.levelChecker.indexOf($scope.levelChecker));

  // .....continue function with index stored
});