Json返回[object object]而不是array
I have json data being fed into a Sencha touch app. Here's the json:
我将json数据输入到Sencha触摸应用程序中。这是json:
http://pastie.org/2622260 - (modified for an example, of course)
http://pastie.org/2622260 - (当然是为一个例子而修改)
When I return the "images" and console.log it, it returns the following:
当我返回“images”和console.log时,它返回以下内容:
images: "[object Object],[object Object],[object Object],[object Object],[object Object]"
Rather than the URLs.
而不是URL。
My json encoder looks like this (I'm pulling the data out of a Wordpress site):
我的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();
What I am looking for it to do is to return the array of image urls, rather than the [object object] that I am currently getting.
我正在寻找的是返回图像网址数组,而不是我目前得到的[对象对象]。
EDIT: Here is the sencha code I'm using to try to pull the imageurl out:
编辑:这是我用来尝试拉出图像的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,
});
4 个解决方案
#1
1
Update: Sorry, for the irrelevant example I had given
更新:对不起,对于我给出的不相关的例子
Where is your pages[i].update(this.record.data.images);
?
你的网页在哪里[i] .update(this.record.data.images); ?
You can try the following -
您可以尝试以下方法 -
var numberOfPages = this.record.data.length;
// Create pages for the carousel
var pages = [];
for (var i=0; i<numberOfPages; i++) {
var tmp = new Ext.Component({
id: 'page'+i,
cls: 'page',
tpl: '<tpl for=".">{imageurl}</tpl>'
});
tmp.update(this.record.data[i].images);
pages.push(tmp);
}
更多相关文章
- Python学习/复习神器-->各种方法/技巧在哪用和典型例子(一)
- Python 浅拷贝和深拷贝使用例子
- python打印列表的下标和值的例子:
- python2.7练习小例子(十二)
- 创建链表的小例子
- LNMP(Linux+Nginx+Mysql+PHP)环境下安装yaf框架并编写一个MVC例子
- 简单统计报表例子(存储过程)
- unity连接数据库MySQL简单例子
- webgote的例子(6)SQL注入(盲注)