EXTJS,如何使用 PHP 创建的 JSON 数据为 XTemplate 创建数据

发布于 2025-01-02 14:58:01 字数 1381 浏览 3 评论 0原文

我有一个包含 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

诗酒趁年少 2025-01-09 14:58:01

您的数据视图缺少强制配置“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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文