我在angularjs中有下面的代碼,但是當我想要我的數組的長度爲0時,它的顯示undefined請檢查下面的代碼,這就是爲什麼我的第二個循環無法運行。 - 在角度如何解決這個問題類型的人幫我請如何獲得angularjs的長度,因爲我的第二個循環沒有運行的長度
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] .length'處的值是一個js對象,而js對象沒有任何稱爲'length'的屬性。你可以使用像Object.keys(current_schedules [0]).length這樣的東西。 – Gaurav
不,他顯然有陣列數組:'[[{...},{...},{...}],[{...},{...},{...} ]]' – Leguest
@Leguest我們不知道OP是否在預先過濾數據。但通過查看'console.log',它顯然看起來像一個對象。 – Gaurav