【问题标题】:How to call a function from tpl in ExtJs如何在 ExtJs 中从 tpl 调用函数
【发布时间】:2020-10-16 19:29:55
【问题描述】:

我正在使用 dataview 控件,我需要从它的 tpl 调用一个函数。 以下是我的代码,但它不起作用。

                                        xtype: 'dataview',
                                        scrollable: true,
                                        tpl: new Ext.XTemplate(
                                            '<tpl for=".">',
                                            '<div class="messageTbl">',
                                            '<table style="width: 100%;">',                                             
                                            '<tr><td>{[this.formatDate(CreationDate)]}</td><tr/>',                                              
                                            '</table>',
                                            '</div>',
                                            '</tpl>',
                                            { 
                                                formatDate: function (date) {
                                                    return date;
                                                    }
                                                },
                                            }
                                        ),

【问题讨论】:

    标签: extjs extjs7


    【解决方案1】:

    formatDate 函数中有语法错误。

    {
        xtype: 'dataview',
        scrollable: true,
        tpl: new Ext.XTemplate(
            '<tpl for=".">',
            '<div class="messageTbl">',
            '<table style="width: 100%;">',
            '<tr><td>{[this.formatDate(CreationDate)]}</td><tr/>',
            '</table>',
            '</div>',
            '</tpl>',
            {
                formatDate: function (date) {
                    return date;
                }
            }
        )
    }
    

    【讨论】:

    • 在中吗?
    • 我们可以在同一个例子中获得索引吗,@norbeq?
    【解决方案2】:

    在同一个例子中请求索引:

    这是在 XTemplate 文档的摘要部分吗?

    XTemplate Documentation

    var tpl = new Ext.XTemplate(
        '<p>Kids: ',
        '<tpl for=".">',       // process the data.kids node
            '<p>{#}. {name}</p>',  // use current array index to autonumber
        '</tpl></p>'
    );
    tpl.overwrite(panel.body, data.kids); // pass the kids property of the data object
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-06
      • 2018-07-02
      • 1970-01-01
      相关资源
      最近更新 更多