【发布时间】:2011-10-01 14:51:29
【问题描述】:
我将 json 数据输入到 Sencha 触摸应用程序中。这是json:
http://pastie.org/2622260 - (当然是修改为示例)
当我返回“图像”并 console.log 时,它会返回以下内容:
images: "[object Object],[object Object],[object Object],[object Object],[object Object]"
而不是 URL。
我的 json 编码器看起来像这样(我从 Wordpress 网站中提取数据):
case 'posts':
foreach(get_posts('numberposts=50&category=') as $post) {
$count = 0;
$imgurl = array();
foreach( get_group('Photo', $post->ID) as $images){
$count++;
$imgurl[] = array(
'count'=>$count,
'imageurl'=>get('photo_image_file', $count, 1, false, $post->ID),
);
}
$json['posts'][] = array(
'id'=>$post->ID,
'title'=>$post->post_title,
'body'=>apply_filters('the_excerpt', $post->post_content),
'date'=>$post->post_date,
'user'=>get_userdata($post->post_author)->user_firstname,
'images'=>$imgurl
);
}
}
header('Content-type: application/json');
echo json_encode($json);
exit();
我正在寻找它做的是返回图像 url 的数组,而不是我目前得到的 [object object]。
编辑:这是我用来尝试提取 imageurl 的 sencha 代码:
console.log(this.record.data);
console.log(this.record.data.images);
console.log(this.record.data.images.length);
var numberOfPages = this.record.data.images.length;
// Create pages for the carousel
var pages = [];
for (var i=0; i<numberOfPages; i++) {
pages.push(new Ext.Component({
id: 'page'+i,
cls: 'page',
tpl: '<tpl for=".">{imageurl}</tpl>',
//html:'test',
}));
}
// Create the carousel
this.carousel = new Ext.Carousel({
id: 'carousel',
title:'Gallery',
iconCls:'photos2',
defaults: {
cls: 'card'
},
items: pages,
});
【问题讨论】:
-
这是在IE的调试工具里吗?
-
你是加入阵列还是什么?只有在将对象转换为字符串时才会得到这个。
标签: php javascript json sencha-touch