开发者

Extjs4 Creating a mixin

开发者 https://www.devze.com 2023-03-05 22:45 出处:网络
Im trying to create a mixing for Ext.grid.Panel components. This is how I have attempted to do it: Ext.define(\'myMixin\', {

Im trying to create a mixing for Ext.grid.Panel components. This is how I have attempted to do it:

Ext.define('myMixin', {
    myFunc:function(){
        console.log('completed!');
    }
});

Ex开发者_StackOverflow社区t.grid.Panel.mixin('newmixin','myMixin');

The result of this is a mixin has been added to grid components, but the value is undefined. Hopefully I have missed something simple, but some help would be much appreciated.


Remember that Ext.define completes asynchronously. I don't know what Ext.grid.Panel.mixin is, as this does not exist in ExtJS 4.0.1, but you might try adding the mixin within the callback parameter of Ext.define:

Ext.define('myMixin', {
    myFunc:function(){
        console.log('completed!');
    }
}, function() {
    Ext.grid.Panel.mixin('newmixin','myMixin');
});


I have solved the problem, but im still not 100% sure of the reason. If somebody can explain im more than happy to mark them as the answer.

I did the following:

Ext.grid.Panel.mixin('newmixin',Ext.define('myMixin', {
    myFunc:function(){
        console.log('completed!');
    }
}));


Have you tried to add your mixin declaratively?

Ext.define('Path.to.MyMixin', {
    someFunc: function () {return 0;}
});

And then, in your grid:

Ext.define('Path.to.MyGrid', {
    extend: 'Ext.grid.Panel',
    mixins: ['Path.to.MyMixin'],
    ...
});
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号