2015-01-21 34 views
2

在javascript数组中,包含值(即;类型是对象)。该对象包含另一个值数组。这个数组内有3个对象。而对象有一些变量。如何一个变量推到另一个数组在javascript如何访问javascript数组中的responsedata包含对象

var studentData = new Array(); 

success: function(responseData) { 
    $.each(responseData, function(index, item) { 
     studentData.push(responseData.markMasterList(0).markMasterDetails(i).student.name); 

responseData显示..

Array[5] 
>0: Object 
    >markArray: Array[1] 
     >0: Object 
     >markDetailsArray: Array[10] 
      >0: Object 
       >student: Object 
        >name //How to push this variable to studentData 
      >1: Object 
      >2: Object 
      >3: Object 
>1: Object 

我试图与这一个,但在控制台上有错误

studentData.push(responseData.markMasterList(0).markMasterDetails(i).student.name); 

错误显示:

Uncaught TypeError: object is not a function

回答

0

没有更多的片段,我只能猜测,但你可能错过了数组语法。

你需要[]引用数组(/对象)键,不()

studentData.push(responseData.markMasterList[0].markMasterDetails[i].student.name); 

(我知道,你的问题指的是物体,但在JS,数组和对象有很多共同点Fe:)

var a = { 1 : "a" , 2 : "b" }; 
a[ 1 ] // Gives "a" 
相关问题