如何动态为widgetcolumn设置不同的TPL

发布于 2025-01-17 13:03:11 字数 1278 浏览 2 评论 0原文

朋友们! 我有一个网格,带有一个小部件列。我从服务器获取商店的数据。 我为每一行获取不同的模板,并尝试在我的小部件中设置这些模板。但是,我无法显示模板中的数据。

这是我的示例小提琴 https://fiddle.sencha.com/#fiddle/3j41& ;view/editor

我希望第二列显示具有不同模板的数据。我看到的不是数据而是{testName}。 在第三列中一切正常,但它是静态数据

你能帮我理解出了什么问题吗?

我的结果:

“在此处输入图片描述"

我的商店:

var store = Ext.create('Ext.data.Store', {
    fields: ['name', 'tplConfig'],
    data: [{
        name: 'Test 1',
        tplConfig: {
            tplBody: '<div><b>Name:</b> {testName}</div> <div>any text</div>',
            tplData: {
                testName: 'Alex'
            }
        }
    }  ]
});
 

我的网格:

{
    xtype: 'grid',
    title: 'Widget Column Demo',
    store: store,
    columns: [
.....
 {
     xtype: 'widgetcolumn',
     text: 'Dynamic',
     width: 120,
     dataIndex: 'tplConfig',
     widget: {
         xtype: 'component',
         tpl: '{tplBody}',
         //data: '{tplData}' //it's not working
            }
        } 
.......
    ] 
}

friends!
I have a grid, with a widget column. I get the data for the store from the server.
I get different templates for each row and try to set these templates in my widget. However, I am not able to display the data in the templates.

Here is my example fiddle https://fiddle.sencha.com/#fiddle/3j41&view/editor

I expect the second column to display data with different templates. Instead of data I see {testName}.
In the third column everything works, but it's static data

Can you help me understand what's wrong?

My result:

enter image description here

My store:

var store = Ext.create('Ext.data.Store', {
    fields: ['name', 'tplConfig'],
    data: [{
        name: 'Test 1',
        tplConfig: {
            tplBody: '<div><b>Name:</b> {testName}</div> <div>any text</div>',
            tplData: {
                testName: 'Alex'
            }
        }
    }  ]
});
 

My grid:

{
    xtype: 'grid',
    title: 'Widget Column Demo',
    store: store,
    columns: [
.....
 {
     xtype: 'widgetcolumn',
     text: 'Dynamic',
     width: 120,
     dataIndex: 'tplConfig',
     widget: {
         xtype: 'component',
         tpl: '{tplBody}',
         //data: '{tplData}' //it's not working
            }
        } 
.......
    ] 
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

云仙小弟 2025-01-24 13:03:11

您可以使用渲染器:

        {
            xtype: 'gridcolumn',
            text: 'Dynamic',
            width: 120,
            dataIndex: 'tplConfig',
            renderer: function(tplConfig) {
                var t = new Ext.Template(tplConfig.tplBody);
                
                return t.apply(tplConfig.tplData);
            }
        }

或用作1衬里:

                return new Ext.Template(tplConfig.tplBody).apply(tplConfig.tplData);

You can use renderer:

        {
            xtype: 'gridcolumn',
            text: 'Dynamic',
            width: 120,
            dataIndex: 'tplConfig',
            renderer: function(tplConfig) {
                var t = new Ext.Template(tplConfig.tplBody);
                
                return t.apply(tplConfig.tplData);
            }
        }

or as a 1 liner:

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