当我打印这个:console.log( response );
它给了我这个 json 数组:
{
"myStudentId":17,
"myName":"beng",
"myAge":38,
"myAddress":"Los Angeles, California, USA.",
"myGender":"Female",
"myReligion":"Catholic",
"myStatus":"boom",
"myOccupation":"Actress",
"myEducationLevel":"Undefined",
"graduate":true
}
我想访问该graduate
值。到目前为止我尝试的是:
console.log( response["graduate"] );
console.log( response.graduate );
但这一切都回来了undefined
。有没有办法做到这一点?如果可能的话,我不想使用循环。如果可能的话,我想通过密钥访问它。
编辑:
我正在使用x-editable 成功方法进行回调。
$(this).editable({
pk: pk,
name: id,
url: '../admin/edit_studentInfo.do',
validate: function( value ) {
if($.trim( value ) == '') {
return 'This field is required';
} else if( isNaN( value ) && id == 'age' ) {
return 'Only accepts numbers';
}
},
success: function(response, newValue) { // call back
var test = response;
console.log( JSON.stringify(response) );
console.log( response );
console.log( response["graduate"] );
console.log( response["myName"] + ', ' + response.myName );
}
});
我包括了我的可编辑初始化和测试