繁体   English   中英

是否可以将两个Ext.XTemplate组合在一起?

[英]Is it possible to combine two Ext.XTemplate together?

我有一个xtype,它接受两个将应用于一组值的Ext.XTemplates(一个是必需的,一个是可选的)。 不幸的是,我无法实现这一点,因为最后运行的模板将覆盖值。 是否可以将XTemplate附加到另一个模板中,或使其在一组值上一个接一个地运行而不破坏先前应用的模板?

这是我的Ext.grid.Column扩展类:

LinkColumn = Ext.extend(Ext.grid.Column,{

    href: '',
    additionalTemplate: '',
    forceApplyTemplate:false,
    dateFormat: 'm/d/y H:i',

    constructor: function(config){
        Ext.QuickTips.init();

        var tpl = new Ext.XTemplate(
            '<tpl if="this.hasValue('+config.dataIndex+') == true">',
                '<tpl if="this.isDate('+config.dataIndex+') == false">',
                    '<a href="'+config.href+'">{'+config.dataIndex+'}</a>',
                '</tpl>',
                '<tpl if="this.isDate('+config.dataIndex+') == true">',
                    '<a href="'+config.href+'">{[fm.date(values.'+config.dataIndex+',"'+this.dateFormat+'")]}</a>',
                '</tpl>',
            '</tpl>',
            {
                compiled: true,
                hasValue: function(value){
                    return !Ext.isEmpty(value);
                },
                isDate: function(value){
                    return Ext.isDate(value);
                }
            }
        );

        LinkColumn.superclass.constructor.call(this,config);
        if (Ext.isEmpty(this.href)) { throw new Ext.Error('LinkColumn: href property is required') };

        this.renderer = function(value, p, r){
            if (!Ext.isEmpty(this.additionalTemplate)){
                var moreTemplate = (!Ext.isPrimitive(this.additionalTemplate) && this.additionalTemplate.compile) ? this.additionalTemplate : new Ext.XTemplate(this.additionalTemplate);
                value = (!Ext.isEmpty(moreTemplate)) ? moreTemplate.apply(r.data) : value;
                value = moreTemplate.apply(r.data);
            };
            //here where value gets overwritten:
            value = tpl.apply(r.data);

            return value;

        };
    },
});

值是template.apply返回的HTML字符串,对吗? 你不能简单地做:

value += tpl.apply(r.data);

哪个将第二个模板的结果添加到第一个模板的结果中?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM