我有这样的代码:
var my = {};
(function () {
var self = this;
this.sampleData = { };
this.loadData = function() {
$.getJSON('http://api.flickr.com/services/feeds/photos_public.gne?jsoncallback=?',
{tags: "cat", tagmode: "any", format: "json"},
function(data){
self.sampleData = data;
}
);
};
}).apply(my);
my.loadData();
console.log(my.sampleData); // {}问题是my.sampleData什么都没有。
请在此处尝试此示例:http://jsfiddle.net/r57ML/
发布于 2012-04-18 18:17:09
(function () {
var self = this;
this.sampleData = {};
this.loadData = function() {
$.getJSON('http://api.flickr.com/services/feeds/photos_public.gne?jsoncallback=?',
{tags: "cat", tagmode: "any", format: "json"},
function(data){
self.sampleData = data;
console.log(my.sampleData); // you get sample data after ajax response
},
'json');
};
}).apply(my);
my.loadData();https://stackoverflow.com/questions/10207297
复制相似问题