Sencha Touch 2:扩展XTemplate-我可以继承parents成员函数吗

Sencha Touch 2: Extending XTemplate - can I inherit parents member functions?

本文关键字:parents 继承 成员 函数 我可以 XTemplate- Touch 扩展 Sencha      更新时间:2023-09-26

我想知道是否有方法访问XTemplate的成员函数集?我正在扩展一个视图,并希望覆盖XTemplate,但希望保留父XTemplate的成员函数。

这里有一个例子-我的基类:

Ext.define( 'my.view', {
xtype: 'myview',
config: {
    itemTpl: new Ext.XTemplate(
    [
            '<p>Name: {name}</p>',
            '<p>Kids: ',
            '<tpl for="kids">',
                '<tpl if="this.isGirl(name)">',
                    '<p>Girl: {name} - {age}</p>',
                '</tpl>',
                 // use opposite if statement to simulate 'else' processing:
                '<tpl if="this.isGirl(name) == false">',
                    '<p>Boy: {name} - {age}</p>',
                '</tpl>',
                '<tpl if="this.isBaby(age)">',
                    '<p>{name} is a baby!</p>',
                '</tpl>',
            '</tpl></p>'
     ].join( "" ),
    {
        // XTemplate configuration:
        compiled: true,
        // member functions:
        isGirl: function(name){
           return name == 'Sara Grace';
        },
        isBaby: function(age){
           return age < 1;
        }
    }
    );
  }
});

"孩子"基本上应该是什么样子:

Ext.define( 'my.subview', {
xtype: 'myview',
extend: 'my.view',
config: {
    itemTpl: new Ext.XTemplate(
    [
            '<p>Something completely different here</p>'
     ].join( "" ),
    //this.superclass.getMemberFunctions()
    );
  }
});

提前!

您不能按照前面描述的方式来做,但也许您可以采取另一种方法。

与其期望XTemplate继承功能(我真的不确定它能做到这一点),不如在可以重用它们的地方定义成员属性/函数。例如:

Ext.define( 'my.view', {
    xtype: 'myview',
    config: {
        xtemplateStuff : {
            // XTemplate configuration:
            compiled: true,
            // member functions:
            isGirl: function(name){
               return name == 'Sara Grace';
            },
            isBaby: function(age){
               return age < 1;
            }
        }
    },
    initialize : function() {
        this.setItemTpl(new Ext.XTemplate([
            'stuff...',
            this.getXtemplateStuff()
        ]));
    }
});

由于config中的任何内容都将被继承,因此您可以在子视图中执行此操作:

Ext.define( 'my.subview', {
    extend: 'my.view',
    initialize : function() {
        this.setItemTpl(new Ext.XTemplate([
            'different stuff...',
            this.getXtemplateStuff()
        ]));
    }
});