EXTJS,如何使用 PHP 创建的 JSON 数据为 XTemplate 创建数据
我有一个包含 JSON 类型数据的 php 变量。
$list = [{"id":"10","first_name":"first","mi_name":"","last_name":"last","nick_name":"HH"}];
我需要使用 EXT-JS XTemplate 的日期。
我尝试了这个方法,
var myStore = <?php echo $list; ?>;
var myTpl = new Ext.XTemplate(
"<div style='text-align:center'>",
'<tpl for=".">',
'<p> No : {#}</p>',
'<p>{first_name} {$last Name}</p>',
"</tpl>",
"</div>",
{}
);
var myPanel = new Ext.Panel({
border : true,
layout : 'fit',
pageY : 10,
items : new Ext.DataView({
store : myStore,
tpl : myTpl,
autoHeight : true,
emptyText : 'No Data'
})
});
但它不起作用,
我也尝试了这个,
var myStore = Ext.create('Ext.data.JsonStore', {
autoLoad : true,
data : <?php echo $list; ?>
});
它也不起作用。
所以我尝试使用代理获取数据。
var myStore = new Ext.data.JsonStore({
proxy : new Ext.data.HttpProxy({
url : './index.php?action=getList' //it return same to $list
}),
fields : [
{name : 'first_name', type : 'string'},
{name : 'last_name', type : 'string'}
],
autoLoad : true
});
它有效!
嗯...
所以我的问题是如何使用 JSON 类型 php 变量创建数据。 (如果可以的话我不想使用代理来获取数据)
帮帮我吧~!
I hava a php variable that contain JSON type data.
$list = [{"id":"10","first_name":"first","mi_name":"","last_name":"last","nick_name":"HH"}];
and I need to use the date for EXT-JS XTemplate.
I tried this way,
var myStore = <?php echo $list; ?>;
var myTpl = new Ext.XTemplate(
"<div style='text-align:center'>",
'<tpl for=".">',
'<p> No : {#}</p>',
'<p>{first_name} {$last Name}</p>',
"</tpl>",
"</div>",
{}
);
var myPanel = new Ext.Panel({
border : true,
layout : 'fit',
pageY : 10,
items : new Ext.DataView({
store : myStore,
tpl : myTpl,
autoHeight : true,
emptyText : 'No Data'
})
});
but it does not work,
also I tried this,
var myStore = Ext.create('Ext.data.JsonStore', {
autoLoad : true,
data : <?php echo $list; ?>
});
it does not work either.
so I tried to get the data using proxy.
var myStore = new Ext.data.JsonStore({
proxy : new Ext.data.HttpProxy({
url : './index.php?action=getList' //it return same to $list
}),
fields : [
{name : 'first_name', type : 'string'},
{name : 'last_name', type : 'string'}
],
autoLoad : true
});
and It works!
Hmm...
so my question is how can I create the data with JSON type php variable.
(I do not want to use proxy to get data if I can)
help me~!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的数据视图缺少强制配置“
itemSelector
”有关详细信息,请阅读 sencha 文档 Sencha ExtJS 4 数据视图
Your dataview is missing the mandatory config "
itemSelector
"For more info, please read the sencha documentation Sencha ExtJS 4 dataview