如何在 angularjs 中获取长度,因为我的第二个循环的长度不是 运行
how to get length in angularjs because of length my second loop not run
我在 angularjs 中有以下代码,但是当我想要我的数组长度 0 位置时,它的显示未定义请检查下面的代码,这就是为什么我的第二个循环没有 运行。在 angular 如何解决此类问题 请任何人帮助我
this.current_engineer = response.data;
var current_schedules = this.current.schedule;
console.log(current_schedules);
console.log(current_schedules.length);
console.log(current_schedules[0].length);
if (angular.isArray(current_schedules)) {
for (var j = 0; j < current_schedules.length; j++) {
for (var i = 0; i < current_schedules[j].length; i++) //this loop does not run because of length how to get length
{
console.log(current_schedules[j][i].title);
}
}
}
///------------Mongodb Database-----------------------
"schedule" : [
[
{
"_id" : ObjectId("58f76aa9be4d311a78f24f78"),
"sch_end" : ISODate("2017-04-21T00:00:00.000Z"),
"sch_start" : ISODate("2017-04-21T00:00:00.000Z"),
"available" : false,
"title" : "test3"
},
{
"_id" : ObjectId("58f76aa9be4d311a78f24f77"),
"sch_end" : ISODate("2017-04-22T00:00:00.000Z"),
"sch_start" : ISODate("2017-04-22T00:00:00.000Z"),
"available" : false,
"title" : "test4"
},
{
"_id" : ObjectId("58f76aa9be4d311a78f24f76"),
"sch_end" : ISODate("2017-04-23T00:00:00.000Z"),
"sch_start" : ISODate("2017-04-23T00:00:00.000Z"),
"available" : false,
"title" : "test6"
}
],
[
{
"_id" : ObjectId("58f76aa9be4d311a78f24f78"),
"sch_end" : ISODate("2017-04-24T00:00:00.000Z"),
"sch_start" : ISODate("2017-04-24T00:00:00.000Z"),
"available" : false,
"title" : "test9"
},
{
"_id" : ObjectId("58f76aa9be4d311a78f24f77"),
"sch_end" : ISODate("2017-04-25T00:00:00.000Z"),
"sch_start" : ISODate("2017-04-25T00:00:00.000Z"),
"available" : false,
"title" : "test10"
},
{
"_id" : ObjectId("58f76aa9be4d311a78f24f76"),
"sch_end" : ISODate("2017-04-27T00:00:00.000Z"),
"sch_start" : ISODate("2017-04-27T00:00:00.000Z"),
"available" : false,
"title" : "test11"
}
]
],
您的 属性 在 current_schedules[0]
的值是一个 js 对象,而 js 对象没有任何 属性 称为长度。你可以使用类似 Object.keys(current_schedules[0]).length
.
的东西
注意:适用于 IE9+ 和所有其他支持 ES5+ 的现代浏览器。
我在 angularjs 中有以下代码,但是当我想要我的数组长度 0 位置时,它的显示未定义请检查下面的代码,这就是为什么我的第二个循环没有 运行。在 angular 如何解决此类问题 请任何人帮助我
this.current_engineer = response.data;
var current_schedules = this.current.schedule;
console.log(current_schedules);
console.log(current_schedules.length);
console.log(current_schedules[0].length);
if (angular.isArray(current_schedules)) {
for (var j = 0; j < current_schedules.length; j++) {
for (var i = 0; i < current_schedules[j].length; i++) //this loop does not run because of length how to get length
{
console.log(current_schedules[j][i].title);
}
}
}
///------------Mongodb Database-----------------------
"schedule" : [
[
{
"_id" : ObjectId("58f76aa9be4d311a78f24f78"),
"sch_end" : ISODate("2017-04-21T00:00:00.000Z"),
"sch_start" : ISODate("2017-04-21T00:00:00.000Z"),
"available" : false,
"title" : "test3"
},
{
"_id" : ObjectId("58f76aa9be4d311a78f24f77"),
"sch_end" : ISODate("2017-04-22T00:00:00.000Z"),
"sch_start" : ISODate("2017-04-22T00:00:00.000Z"),
"available" : false,
"title" : "test4"
},
{
"_id" : ObjectId("58f76aa9be4d311a78f24f76"),
"sch_end" : ISODate("2017-04-23T00:00:00.000Z"),
"sch_start" : ISODate("2017-04-23T00:00:00.000Z"),
"available" : false,
"title" : "test6"
}
],
[
{
"_id" : ObjectId("58f76aa9be4d311a78f24f78"),
"sch_end" : ISODate("2017-04-24T00:00:00.000Z"),
"sch_start" : ISODate("2017-04-24T00:00:00.000Z"),
"available" : false,
"title" : "test9"
},
{
"_id" : ObjectId("58f76aa9be4d311a78f24f77"),
"sch_end" : ISODate("2017-04-25T00:00:00.000Z"),
"sch_start" : ISODate("2017-04-25T00:00:00.000Z"),
"available" : false,
"title" : "test10"
},
{
"_id" : ObjectId("58f76aa9be4d311a78f24f76"),
"sch_end" : ISODate("2017-04-27T00:00:00.000Z"),
"sch_start" : ISODate("2017-04-27T00:00:00.000Z"),
"available" : false,
"title" : "test11"
}
]
],
您的 属性 在 current_schedules[0]
的值是一个 js 对象,而 js 对象没有任何 属性 称为长度。你可以使用类似 Object.keys(current_schedules[0]).length
.
注意:适用于 IE9+ 和所有其他支持 ES5+ 的现代浏览器。