javascript - Sencha 触摸2 : Extending XTemplate - can I inherit parents member functions?

标签 javascript inheritance sencha-touch-2

我想知道是否有办法访问 XTemplate 的成员函数集?我正在扩展一个 View 并想要覆盖 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;
        }
    }
    );
  }
});

“ child ”基本上应该是什么样子:

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 中的任何内容都将被继承,因此您可以在 subview 中执行此操作:

Ext.define( 'my.subview', {
    extend: 'my.view',

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

关于javascript - Sencha 触摸2 : Extending XTemplate - can I inherit parents member functions?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31111497/

相关文章:

javascript - 如何在单引号内使用单引号

javascript - 将函数附加到左键单击 <listbox> 项目

javascript - 数组未显示在模板中,Meteor

ruby-on-rails - 在继承模型之上添加其他字段并公开所有父类(super class)和子类字段

extjs - Sencha 触摸 2 : How to reference self in class definition

android - 如何处理 sencha touch 应用程序上的设备后退按钮

javascript - 如何使用插件扩展 javaScript 库

ruby 混合 : extend and include

C++,抽象类和继承

sencha-touch - 在 Sencha Touch 的 View 中使用 getComponent 吗?