Sencha Touch Tree Store'对象没有方法getRootNode'

时间:2012-06-27 06:18:38

标签: sencha-touch extjs sencha-touch-2 sencha-architect

我正在使用PhoneGap和Sencha Touch 2开发Android 2.3.3应用程序......

我有一个登录视图,我在其中重定向到我的应用程序中的嵌套列表视图...我使用嵌套列表的内联存储,我将该类型定义为商店的“树”...

我第一次尝试加载应用程序时,当我点击登录时,它给我一个错误...错误如下所示:

Uncaught TypeError: Object [object Object] has no method 'getRootNode' at file:///android_asset/www/sencha/sencha-touch-all.js:15

但是在收到错误之后如果我强行关闭应用并再次打开它,一切正常......

我的代码是:

Login.js

Ext.define("DDLApp.view.Login", {
    //extent panel class
    extend: "Ext.form.Panel",
    //DOM in fieldset
    requires: "Ext.form.FieldSet",
    xtype: 'formLogin',
    id:'loginForm',
    config: {
        scrollable: 'vertical',
        id: 'login',
        items: [
            {
                xtype: "toolbar",
                docked: "top",
            },
            {
                xtype: "toolbar", //Toolbar with heading as login
                docked: "top",
                title: "Login",
                ui:'light',
                id:"idHeaderTwo",
                cls:"clsLoginHeader"                
            }, 
            {
                xtype: 'textfield', //textfield for username
                name: 'Username',
                required: true,
                id:"idUserName",
                cls:"clsUserName",
                useClearIcon: false
           },
            {
                xtype: 'passwordfield', //textfield for password
                name: 'password',
                required: true,
                id:"idPassword",
                cls:"clsPassword",
                useClearIcon: false
            },
            {
                xtype: 'button', //Login button
                text: 'Login',
                ui: 'confirm',
                cls:'btnLogin',
                width:'30%',
                handler: function(SuccessFlag) { //Login button handler
                    ui: 'confirm',
                    console.log('Login Button pressed');
                    var form = Ext.getCmp('login');

                    //get username and password from form elements
                    var user = form.getValues().Username;
                    var pwd = form.getValues().password;

                    var msg = new Ext.MessageBox();

                    onLoad();

                    if(user == "" || pwd == "")
                    {
                        var errMsg = '';
                        if(user == "")
                            {
                                errMsg+= 'Username is required<br/>';
                            }
                        if(pwd == "")
                            {
                                errMsg+= 'Password is required';
                            }
                        msg.show({
                            title: 'LOGIN ERROR',
                            message: errMsg,
                            ui:'light',
                            cls: 'vm_error',
                            showAnimation: 'fadeIn',
                            hideAnimation: 'fadeOut',
                            buttons: [{text:'OK',itemId:'ok'}],
                            fn:function(){
                                Ext.emptyFn();
                            }
                        });
                    }                  
                    else 
                    {
                        form.setMasked({
                            xtype:'loadmask',
                            message:'Loading...'
                        });

                        //Check for network connectivity
                        if(onDeviceReady())
                        {
                        //Fire a json service
                        Ext.util.JSONP.request({
                            url: DDLApp.app.oneTimeServiceUrl,
                            dataType: "jsonp",
                            params: {
                                type:'fetch',
                                username:user,
                                password:pwd
                            },
                            success: function (result) {
                              //if username and password matches
                                if(result.Success == true)
                                {                                                
                                     //setLocalStorage(result);
                                     localStorage.setItem('userName',user);
                                     localStorage.setItem('userPassword',pwd);
                                     localStorage.setItem('totalData',JSON.stringify(result.Data));
                                     localStorage.setItem('userData',JSON.stringify(result.Data.user));
                                     localStorage.setItem('userIncidentData',JSON.stringify(result.Data.incidentList));
                                     localStorage.setItem('impactData',JSON.stringify(result.Data.impact));
                                     localStorage.setItem('incidentTypeData',JSON.stringify(result.Data.incident_type));
                                     localStorage.setItem('categoryData',JSON.stringify(result.Data.category));
                                     localStorage.setItem('statusData',JSON.stringify(result.Data.statusDropdown));

                                     var indexPanel = Ext.create('DDLApp.view.Main');
                                     Ext.Viewport.add(indexPanel);
                                     Ext.Viewport.setActiveItem(indexPanel,{type: 'slide', direction: 'right'});
                                     form.unmask();
                                }
                                else{
                                    msg.show({
                                        title: 'LOGIN ERROR',
                                        message: 'Invalid Username/Password',
                                        ui:'light',
                                        cls: 'vm_error',
                                        showAnimation: 'fadeIn',
                                        hideAnimation: 'fadeOut',
                                        buttons: [{text:'OK',itemId:'ok'}],
                                        fn:function(){
                                            Ext.emptyFn();
                                        }
                                    });
                                    form.unmask();
                                }
                            }
                        });
                        }
                        ////If network is not present
                        else
                        {
                            form.unmask();
                            msg.show({
                                title: 'NETWORK CONNECTION ERROR',
                                message: "We're Sorry but it appears your device is not connected to the internet . Please check your internet settings and try again.",
                                ui:'light',
                                cls: 'vm_error',
                                showAnimation: 'fadeIn',
                                hideAnimation: 'fadeOut',
                                buttons: [{text:'Retry',itemId:'retry'}],
                                fn:function(){
                                    window.location.reload();
                                }
                            });
                        }
                    }
                },
            },
            {
                xtype: 'button', //clear button
                text: 'Clear',
                width:'30%',
                ui: 'confirm',
                cls:'btnClear',
                style: 'background:#4A4245;',
                handler: function() {
                    this.up('formpanel').reset(); //reset all form elements
                },
            }
        ]
    },
});

IncidentsList.js

Ext.define("DDLApp.view.IncidentsList", {
    extend: "Ext.Container",
    xtype: 'incidentsList',
    id: 'idIncList',
    requires:[
              'Ext.dataview.NestedList',
              'Ext.data.proxy.Memory',
              'Ext.data.TreeStore',
          ],
    alias:'widget.incidentslist',
    config: {
        id: 'idIncidentList',
        layout:'fit',
        items: [
                {
                    xtype: "toolbar",
                    docked: "top",
                    cls:'clsDDLHeader',
                    items: [
                            {xtype:'spacer'},
                            {   xtype: 'title' ,
                                cls: 'clsRightTitle',
                                id: 'idIncidentsListTitle',
                                title:"Welcome",
                            },
                            ]
                },
                {
                    xtype: "toolbar",
                    ui:'light',
                    id:"idHeaderTwo",
                    cls:"clsHeaderTwo" ,
                        items: [
                                {   xtype: 'title' ,
                                    cls: 'clsLeftTitle',
                                    title: "My Incidents",
                                },
                                {xtype:'spacer'}
                                ]
                },
                {
                    xtype: 'nestedlist',
                    id:'idIncidentList',
                    onItemDisclosure:true,
                    cls:'clsNestedIncidentList',
                    toolbar:{id:'idNestedIncidentList'},
                    loadingText: "Loading Incidents...",
                    emptyText: "<div class=\"empty-text\">No Incidents Found.</div>",
                    getItemTextTpl: function() {
                        var tplConstructor =             
                            '<tpl if="TKT_STATUS_NAME == \'CLOSED\'">'+
                            '<div class="vm_statusRed">'+
                            '</tpl>'+
                            '<tpl if="TKT_STATUS_NAME == \'OPENED\'">'+
                            '<div class="vm_statusYellow">'+
                            '</tpl>'+
                            '<tpl if="TKT_STATUS_NAME == \'ASSIGNED\'">'+
                            '<div class="vm_statusGreen">'+
                            '</tpl>'+
                            '<tpl if="TKT_STATUS_NAME == \'PENDING\'">'+
                            '<div class="vm_statusRed">'+
                            '</tpl>'+
                            '<tpl if="TKT_STATUS_NAME == \'RESOLVED\'">'+
                            '<div class="vm_statusOrange">'+
                            '</tpl>'+
                            '<tpl if="TKT_STATUS_NAME == \'REOPEN\'">'+
                            '<div class="vm_statusYellow">'+
                            '</tpl>'+
                            '<div class="vm_dvList"><h4 class="vm_txtName"><span class="vm_listHeader"><label>Inci.#{TKT_ID} by </label><label class="vm_txtFirstName"><i>{FIRST_NAME:ellipsis(15, true)}</i></label></span><div class="date vm_clsDate">{CREATED_ON:date("d-M-y H:i")}</div></h4>'+
                            '<div class="vm_title">{TKT_SUBJECT}</div>'+
                            '<div class="vm_subDesc">{TKT_DESC}</div></div></div>';
                        return tplConstructor;
                    },

                    store: {
                        type: 'tree',

                        fields: ['TKT_ID', 'CREATED_ON', 'FIRST_NAME', 'TKT_STATUS_NAME', 'TKT_SUBJECT', 'TKT_DESC', 'SEV_DESC', 'SERVICE_NAME', 'CATEGORY_NAME', {
                            name: 'leaf',
                            defaultValue: true
                        }],

                        root: {
                            leaf: false
                        },

                        data : localStorage.userIncidentData,

                        proxy: {
                            type: 'memory',
                            reader: {
                                type: 'json',
                                rootProperty: 'incidentList'
                            }
                        }
                    },

                    detailCard: {
                        xtype: "fieldset",
                        scrollable: true,
                        id: "idIncidentDetails",
                        items: [
                            {
                                xtype: 'textfield',
                                name: 'TKT_SUBJECT',
                                label: 'Subject',
                                labelAlign: 'top',
                                cls:'vm_textFields',
                                clearIcon:false,
                                disabled:true
                            },
                            {
                                xtype: 'textareafield',
                                name: 'TKT_DESC',
                                label: 'Description',
                                labelAlign: 'top',
                                cls:'vm_textFields',
                                clearIcon:false,
                                disabled:true
                            },
                            {
                                xtype: 'textfield',
                                name: 'SEV_DESC',
                                label: 'Impact',
                                labelWidth:'45%',
                                cls:'vm_textFields',
                                clearIcon:false,
                                disabled:true
                            },
                            {
                                xtype: 'textfield',
                                name: 'SERVICE_NAME',
                                id:'displayIncident',
                                cls:'vm_textFields',
                                label: 'IncidentType',
                                labelWidth:'45%',
                                disabled:true
                            },
                            {
                                xtype: 'textfield',
                                label: 'Category',
                                name: 'CATEGORY_NAME',
                                cls:'vm_textFields',
                                id:'getCategory',
                                labelWidth:'45%',
                                disabled:true
                            },
                    ],
                    },

                    listeners: {
                        itemtap: function(nestedList, list, index, element, post) {
                            this.getDetailCard().items.items[0].setHtml(post._data.TKT_SUBJECT);
                            this.getDetailCard().items.items[1].setHtml(post._data.TKT_DESC);
                            this.getDetailCard().items.items[2].setHtml(post._data.SEV_DESC);
                            this.getDetailCard().items.items[3].setHtml(post._data.SERVICE_NAME);
                            this.getDetailCard().items.items[4].setHtml(post._data.CATEGORY_NAME);
                        }
                    }
                }, 
                {html:'No Incidents Found....',id:'idEmptyText'}],
    }, 
    initialize: function() {
        this.callParent(arguments);
        var incidentStore = Ext.getCmp('idIncidentList').getStore();
        Ext.getCmp("idEmptyText").hide();
        var getLoginData = localStorage.getItem('userData');
        var parseData = JSON.parse(getLoginData);
        var fname = parseData[0].FIRST_NAME;
        var getIncidentData = localStorage.getItem('userIncidentData');
        var parseIncidentData = JSON.parse(getIncidentData);
        this.down("#idIncidentsListTitle").setTitle("Welcome, " + fname);
        if(localStorage.userIncidentData != '[""]')
            {
                Ext.getCmp("idEmptyText").hide();
                incidentStore.setData(localStorage.userIncidentData).load();
            }
        else
            {
                this.down("#inclist").hide();
                this.down("#idEmptyText").show();
                var msg = new Ext.MessageBox();
                msg.show({
                    title: 'NO INCIDENTS FOUND',
                    message: 'No Incidents have reported by this user',
                    ui:'light',
                    cls: 'vm_error',
                    showAnimation: 'fadeIn',
                    hideAnimation: 'fadeOut',
                    buttons: [{text:'OK',itemId:'ok'}],
                    fn:function(){
                        Ext.emptyFn();
                    }
                });
            }
    },
});

我需要尽快摆脱这个错误...我的应用程序中的所有内容从第二次开始工作正常......我认为问题出在我定义的商店...请帮助我伙计们......先谢谢你们...... !!!

2 个答案:

答案 0 :(得分:2)

我的商店是在我的IncidentList视图中自行定义的......

store: {
                type: 'tree',

                fields: ['TKT_ID', 'CREATED_ON', 'FIRST_NAME', 'TKT_STATUS_NAME', 'TKT_SUBJECT', 'TKT_DESC', 'SEV_DESC', 'SERVICE_NAME', 'CATEGORY_NAME', {
                    name: 'leaf',
                    defaultValue: true
                }],

                root: {
                    leaf: false
                },

                data : localStorage.userIncidentData,

                proxy: {
                    type: 'memory',
                    reader: {
                        type: 'json',
                        rootProperty: 'incidentList'
                    }
                }
            },

答案 1 :(得分:0)

这是真的:对象[object Object]没有方法getRootNode ST2中不再提供此方法,请查看API docs

实际上,这是ST代码中唯一保留此方法的地方。尝试在TreeStore中编辑sencha代码

removeAll: function() {
       this.getRootNode().removeAll(true);
       this.callParent(arguments);
},

removeAll: function() {
        this.getRoot().removeAll(true);
        this.callParent(arguments);
    },