开发者

Extjs layout extension causing error in ext-all.js

I am trying to learn Extjs and I am immediately coming up with an issue. My Html has ext-base.js and ext-all.js correctly included. I then h开发者_如何学Goave the following in my js file:

Ext.BLANK_IMAGE_URL = '<%= Url.Content("~/Content/ext/images/default/s.gif") %>';
Ext.ns('MyNamespace');

Ext.onReady(function() {
    alert("onReady() fired");
});

So far everything is working, no errors and the alert is thrown correctly. I then add the following code after onReady:

MyNamespace.BaseLayout = Ext.Extend(Ext.Viewport({
    layout: 'border',
    items: [
        new Ext.BoxComponent({
            region: 'north',
            height: 32,
            autoEl: {
                tag: 'div',
                html: '<p>North</p>'
            }
        })
    ]
}));

This causes the following javascript error in chrome:

Uncaught TypeError: Object #<an Object> has no method 'addEvents'       ext-all.js:7
Ext.Component       ext-all.js:7
Ext.apply.extend.K       ext-base.js:7
Ext.apply.extend.K       ext-base.js:7
Ext.apply.extend.K       ext-base.js:7
(anonymous function)       MyApp.js:13 (pointing to the Ext.Extend line)

If I take the Viewport code and put it directly into the OnReady function it (like the following)

Ext.onReady(function () {
    var bl = new Ext.Viewport({
        layout: 'border',
        items: [
        new Ext.BoxComponent({
            region: 'north',
            height: 32,
            autoEl: {
                tag: 'div',
                html: '<p>North</p>'
            }
        })
    ]
    });
});

It works. Can anyone clue me in to what I am doing wrong with the Extend method?


To fix your code, the issue is simply bad syntax in the Extend statement. You need a comma after Ext.Viewport, not an extra () pair:

MyNamespace.BaseLayout = Ext.Extend(Ext.Viewport, {
    layout: 'border',
    items: [
        new Ext.BoxComponent({
            region: 'north',
            height: 32,
            autoEl: {
                tag: 'div',
                html: '<p>North</p>'
            }
        })
    ]
});

However, I'd suggest taking @r-dub's advice and reading up more on what you're trying to do.


Here's a bit more complicated example of what you're trying to accomplish. I'd strongly suggest taking a look at Saki's 3 part series in building large apps with ExtJS, it'll help you understand how it use extend properly to create re-usable components.

Ext.ns('MyNamespace');

MyNamespace.BaseLayout = Ext.extend(Ext.Viewport, {
    initComponent:function() {
        var config = {
            layout: 'border',
            items: [
                new Ext.BoxComponent({
                    region: 'north',
                    height: 32,
                    autoEl: {
                        tag: 'div',
                        html: '<p>North</p>'
                    }
                })
            ]
        };
        Ext.apply(this, Ext.apply(this.initialConfig, config));

        MyNamespace.BaseLayout.superclass.initComponent.apply(this,arguments);
    }//end initComponent

});

//this will give you an xtype to call this component by.
Ext.reg('baselayout',MyNamespace.BaseLayout);

Ext.onReady(function() {
    new MyNamespace.BaseLayout({});
});


ExtJS recommend the use of define instead of extend. Here is how a similar example works with define:

 Ext.define('Grid', {
    extend: 'Ext.grid.Panel',
    config: {          
        height: 2000        
    },

    applyHeight: function (height) {           
            return height;
    }       
});

new Grid({
    store: store,
    columns: [{
        text: 'Department',
        dataIndex: 'DepartmentName',
        renderer: function (val, meta, record) {
            return '<a href="DepartmentEmployees/' + record.data.ID + '">' + record.data.DepartmentName + '</a>';
        },
        width: 440,
        flex: 1,
        filter: 'string',
        sortable: true,
        hideable: false
    }, {
        text: 'Department Code',
        dataIndex: 'DepartmentKey',
        width: 100,
        flex: 1,
        filter: 'string',
        sortable: true,
        hideable: false
    }, {
        text: 'Main Phone',
        dataIndex: 'MainPhone',
        flex: 1,
        filter: 'string',
        sortable: true,
        hideable: false
    }, {
        text: 'Room',
        dataIndex: 'RoomLocation',
        flex: 1,
        filter: 'string',
        sortable: true,
        hideable: false
    }, {
        text: 'Hideway Location',
        dataIndex: 'HideawayLocation',
        flex: 1,
        filter: 'string',
        sortable: true,
        hideable: false
    }, {
        text: 'Hideway Phone',
        dataIndex: 'HideawayPhone',
        flex: 1,
        filter: 'string',
        sortable: true,
        hideable: false
    }, {
        text: 'Has OEC',
        dataIndex: 'OECFlag',
        xtype: 'checkcolumn',
        width: 50,
        filter: {
            type: 'boolean',
            active: true
        },
        flex: 1,
        sortable: true,
        hideable: false
    },
       {
           text: 'Action',
           dataIndex: 'ID',
           renderer: function (value) {
               return '<a href="DepartmentEdit/' + value + '">Edit</a>';
           },
           hideable: false
       }],
    forceFit: false,
    split: true,
    renderTo: 'departmentSearchGrid',
    frame: false,
    width: 1300,
    plugins: ['gridfilters']
});

I used the following post as a reference: http://docs.sencha.com/extjs/5.0/core_concepts/classes.html

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜