【发布时间】:2018-04-28 22:52:13
【问题描述】:
我有json data here。我正在尝试像这样在property_more_images 中获取数据:
getItemImages: function(pid) {
xhr.simpleCall({
query:{
com_option:"item",
item_get_id:pid
},
func:'timeline'
}, function(response) {
if (response.err_code === 0) {
console.log(response.data[0].property_more_images);
var arr = response.data[0].property_more_images;
notice_obj = [];
for (var i = 0, l = arr.length; i < l; ++i) {
notice_obj.push(arr[i]);
}
return notice_obj.join(' ,');
}
});
}
然后像这样使用getItem 函数:
getItem: function(pid) {
var $this = $$('.time-line-content .item-content[data-id="'+ pid +'"]');
var item = {
id: $this.data('id'),
nickname: $this.find('.item-header .detail .nickname').html()
};
item.propslider = this.getItemImages(pid);
var output = TM.renderTplById('itemTemplate', item);
$$('#itemContent').html(output);
}
到目前为止,我的console.log 给了我预期的 json 数据。当我在getItem 函数中调用getItemImages 函数时,我似乎没有得到任何数据。 getItemImages 函数有问题。我不知道是什么。
【问题讨论】:
-
getItemImages是异步调用,不能简单的return。您需要等待结果或在回调函数中使用结果 -
谢谢@santi 完全忘记了我稍后会发布解决方案