我有一个带有一些动态键的对象。我能够读取密钥名称,但不能读取值:
var response = {
"keyOne": {
"keyChanged": {
"keyTwo": {
"keyINeed": "myData"
}
}
}
}
var myKey = Object.keys(response.keyOne)[0];
var myValue = response.keyOne."something".keyTwo.keyINeed
我该怎么做?
答案 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);
};