Html 获取数组angularjs的父索引

Html 获取数组angularjs的父索引,html,angularjs,Html,Angularjs,我搜索了一下,发现这段代码正是我现在需要的。但这有点不对劲。当我点击alertme按钮时,它的警报为-1,这是错误的。当我单击1时,它是警报-1,它应该是0,因为编号和名称在sectionA中。当我想点击3时,弗兰克·乔马尔·廷邦应该提醒1,因为他在B区?有人帮忙吗?建议?短暂性脑缺血发作 var stud=angular.module(“stud”,[]); stud.controller(“StudentsController”,函数($scope){ "严格使用",; $scope.al

我搜索了一下,发现这段代码正是我现在需要的。但这有点不对劲。当我点击alertme按钮时,它的警报为-1,这是错误的。当我单击1时,它是警报-1,它应该是0,因为编号和名称在sectionA中。当我想点击3时,弗兰克·乔马尔·廷邦应该提醒1,因为他在B区?有人帮忙吗?建议?短暂性脑缺血发作

var stud=angular.module(“stud”,[]);
stud.controller(“StudentsController”,函数($scope){
"严格使用",;
$scope.alertMe=函数(studentGroup){
警报($scope.students.indexOf(studentGroup));
};
$scope.sectionA=[
{
否:1,,
名称:'Brick Med',
},
{
否:2,,
姓名:“科林·克里斯托弗”,
},
];
$scope.sectionB=[
{
否:3,,
姓名:“Frank Joemar Timbang”,
},
{
否:4,,
姓名:“柯蒂斯·扎蒙德”,
}
];
$scope.students=[
$scope.a节,
$scope.b节
];
});

学生
学生
警觉的
{{student.no}{{student.name}
提醒我!

问题在于
索引of
studentGroup
在前两行被正确设置为
0
,在下两行被正确设置为
1
。如果需要节数组,则应使用

$scope.alertMe = function (studentGroup) {
    alert($scope.students[studentGroup]);
};

问题在于
索引
studentGroup
在前两行被正确设置为
0
,在下两行被正确设置为
1
。如果需要节数组,则应使用

$scope.alertMe = function (studentGroup) {
    alert($scope.students[studentGroup]);
};

问题在于
索引
studentGroup
在前两行被正确设置为
0
,在下两行被正确设置为
1
。如果需要节数组,则应使用

$scope.alertMe = function (studentGroup) {
    alert($scope.students[studentGroup]);
};

问题在于
索引
studentGroup
在前两行被正确设置为
0
,在下两行被正确设置为
1
。如果需要节数组,则应使用

$scope.alertMe = function (studentGroup) {
    alert($scope.students[studentGroup]);
};

好的,那么您的问题是,当您只想使用studentGroup作为索引时,您正在使用indexOf()

$scope.alertMe = function (studentGroup) {
     alert($scope.students[studentGroup]); // returns object object in your array
     alert($scope.students[studentGroup][0]); /// returns sectionA object1
     alert($scope.students[studentGroup][0].name); /// returns sectionA object1 name
};
我修改了你的html,所以它更容易阅读,但你的原始资料应该仍然有效

   <tbody ng-repeat="studentGroup in students" ng-init="studentsIndex = $index">
    <tr ng-repeat="student in studentGroup">
        <td>{{student.no}} {{student.name}}</td>
        <td><button ng-click="alertMe(studentsIndex)">Alert me!</button></td> 
    </tr>
    </tbody>

{{student.no}{{student.name}
提醒我!

如果这不是您想要的,并且您确实想要提醒索引,那么让我解释一下indexOf是如何工作的。该方法将采用一个搜索参数,用于在数组中搜索该元素数据。它现在返回-1,因为您为它提供了索引,它将该索引作为索引0和1中的元素数据进行搜索。步骤:执行任意索引=$scope.sectionA,不继续,执行任意索引=$scope.sectionB,不继续。完成后,未找到搜索参数return-1。

好的,所以您的问题是,当您只想使用studentGroup作为索引时,您正在使用indexOf()

$scope.alertMe = function (studentGroup) {
     alert($scope.students[studentGroup]); // returns object object in your array
     alert($scope.students[studentGroup][0]); /// returns sectionA object1
     alert($scope.students[studentGroup][0].name); /// returns sectionA object1 name
};
我修改了你的html,所以它更容易阅读,但你的原始资料应该仍然有效

   <tbody ng-repeat="studentGroup in students" ng-init="studentsIndex = $index">
    <tr ng-repeat="student in studentGroup">
        <td>{{student.no}} {{student.name}}</td>
        <td><button ng-click="alertMe(studentsIndex)">Alert me!</button></td> 
    </tr>
    </tbody>

{{student.no}{{student.name}
提醒我!

如果这不是您想要的,并且您确实想要提醒索引,那么让我解释一下indexOf是如何工作的。该方法将采用一个搜索参数,用于在数组中搜索该元素数据。它现在返回-1,因为您为它提供了索引,它将该索引作为索引0和1中的元素数据进行搜索。步骤:执行任意索引=$scope.sectionA,不继续,执行任意索引=$scope.sectionB,不继续。完成后,未找到搜索参数return-1。

好的,所以您的问题是,当您只想使用studentGroup作为索引时,您正在使用indexOf()

$scope.alertMe = function (studentGroup) {
     alert($scope.students[studentGroup]); // returns object object in your array
     alert($scope.students[studentGroup][0]); /// returns sectionA object1
     alert($scope.students[studentGroup][0].name); /// returns sectionA object1 name
};
我修改了你的html,所以它更容易阅读,但你的原始资料应该仍然有效

   <tbody ng-repeat="studentGroup in students" ng-init="studentsIndex = $index">
    <tr ng-repeat="student in studentGroup">
        <td>{{student.no}} {{student.name}}</td>
        <td><button ng-click="alertMe(studentsIndex)">Alert me!</button></td> 
    </tr>
    </tbody>

{{student.no}{{student.name}
提醒我!

如果这不是您想要的,并且您确实想要提醒索引,那么让我解释一下indexOf是如何工作的。该方法将采用一个搜索参数,用于在数组中搜索该元素数据。它现在返回-1,因为您为它提供了索引,它将该索引作为索引0和1中的元素数据进行搜索。步骤:执行任意索引=$scope.sectionA,不继续,执行任意索引=$scope.sectionB,不继续。完成后,未找到搜索参数return-1。

好的,所以您的问题是,当您只想使用studentGroup作为索引时,您正在使用indexOf()

$scope.alertMe = function (studentGroup) {
     alert($scope.students[studentGroup]); // returns object object in your array
     alert($scope.students[studentGroup][0]); /// returns sectionA object1
     alert($scope.students[studentGroup][0].name); /// returns sectionA object1 name
};
我修改了你的html,所以它更容易阅读,但你的原始资料应该仍然有效

   <tbody ng-repeat="studentGroup in students" ng-init="studentsIndex = $index">
    <tr ng-repeat="student in studentGroup">
        <td>{{student.no}} {{student.name}}</td>
        <td><button ng-click="alertMe(studentsIndex)">Alert me!</button></td> 
    </tr>
    </tbody>

{{student.no}{{student.name}
提醒我!

如果这不是您想要的,并且您确实想要提醒索引,那么让我解释一下indexOf是如何工作的。该方法将采用一个搜索参数,用于在数组中搜索该元素数据。它现在返回-1,因为您为它提供了索引,它将该索引作为索引0和1中的元素数据进行搜索。步骤:执行任意索引=$scope.sectionA,不继续,执行任意索引=$scope.sectionB,不继续。完成,未找到搜索参数返回-1。

我尝试了你的代码,但它向我发出警报[object,object],[object,object]。我尝试了你的代码,但它向我发出警报[object,object],[object,object]。我尝试了你的代码,但它向我发出警报[object,object],[object,object].感谢您向我澄清index0f的工作原理。我运行了您的代码,但它提醒我[object,object],[object,object]。如果您查看我的全部答案,您将看到我给出了如何从这些对象中获取name属性的说明。你必须应用这些技术从这些对象中获得你想要的适当信息