我正在尝试使用专用函数在json中获取特定元素,但我无法弄清楚它为什么不起作用。任何人都可以帮助我吗?
我在这里设置了一个小提琴: http://jsfiddle.net/jonigiuro/N5TTM/2/
CODE:
var data = {
"results":[
{
"reinsurance":{
"africa":{
"one":{
"name":"test",
"address":"test street",
"tel1":"tel1",
"tel2":"tel2",
"url":"http://www.google.com"
}
}
}
}
]
}
// FAKE RESPONSE
var AjaxInfo = {
init : function() {
this.bindEvents();
},
bindEvents : function() {
var self = this;
$(document).ready(function() {
self.renderData( 'reinsurance', 'africa', 'one' );
})
},
renderData : function( category, country, name ) {
console.log(data.results[0]); //ok
console.log(data.results[0].category); //I pass 'insurance' as a category but it returns "undefined" because it looks for "category" instead
}
}
AjaxInfo.init();
答案 0 :(得分:1)
答案 1 :(得分:0)
答案 2 :(得分:0)