2014-10-01 77 views
1
var selectCheckbox = []; 
for (i = 0; i <= escConfigForm.chapters.size; i++) { 
    if (escConfigForm.chapters['i']) { 
     selectCheckbox.push({ 
      id: $scope.chapters['i'].id, 
      name: $scope.chapters['i'].name 
     }); 
    } 
    console.log(selectedCheckbox); 

我创建一个数组来返回对象到它其中来自$scope.chapters 它看起来像:iterrating通过对象和数组存储

[{"name":"Chapter 9: Negative Messages","id":"832115"},{"name":"Chapter 13: Proposals, Business Plans, and Formal Business Reports","id":"832124"}]. 

同时我想他们escConfigForm.chapters比较哪个给我看一个物体(0:true 1:true 2:true);

escConfigForm.chapters.size/escConfigForm.chapters.length好像是undefined

+1

对象没有'length'属性,但是可以执行'Object.keys(object).length'。 – elclanrs 2014-10-01 01:51:10

回答

0

这是你在JS中遇到的那些奇怪复杂的事情之一。例如,Object.keys()将返回对象中的字段,其中原型中的字段为以及

Angular拥有angular.forEach便利方法,它具体说明它不会遍历继承的属性。唉,我怀疑订单是有保证的,但是也可能是这样。 。 。