从对象获取子节点

时间:2016-11-07 11:43:46

标签: jquery json

我有一个带有一些动态键的对象。我能够读取密钥名称,但不能读取值:

var response = {
    "keyOne": {
        "keyChanged": {
            "keyTwo": {
                "keyINeed": "myData"
            }
        }
    }
}

var myKey = Object.keys(response.keyOne)[0];
var myValue = response.keyOne."something".keyTwo.keyINeed

我该怎么做?

1 个答案:

答案 0 :(得分:1)

要实现此目的,您需要使用括号表示法,因为您在变量中提供了对象的键。试试这个:



 var createAttendances = function(){
    var stud = StudentResource.get(function(data){
        $scope.students = data.students;
        console.log($scope.students);
    });
    console.log(stud.students);
    console.log($scope.sudents);
};




相关问题