简体   繁体   English

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

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

I have an xtype that accepts two Ext.XTemplates (one required & one optional) that will be applied to a set of values. 我有一个xtype,它接受两个将应用于一组值的Ext.XTemplates(一个是必需的,一个是可选的)。 Unfortunately I'm unable to achieve this as the last template run it will overwrite the values. 不幸的是,我无法实现这一点,因为最后运行的模板将覆盖值。 Is it possible to append an XTemplate into another, or make it run on a set of values one after another without destroying what previous templates applied? 是否可以将XTemplate附加到另一个模板中,或使其在一组值上一个接一个地运行而不破坏先前应用的模板?

Here's my Ext.grid.Column extended class: 这是我的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;

        };
    },
});

Value is the HTML string returned by the template.apply, correct? 值是template.apply返回的HTML字符串,对吗? Can you not simply do: 你不能简单地做:

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

Which would add the results of the second template to the results of the first? 哪个将第二个模板的结果添加到第一个模板的结果中?

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

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