1

我正在使用 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

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

我的代码是:

登录.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
                },
            }
        ]
    },
});

事件列表.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();
                    }
                });
            }
    },
});

我需要尽快摆脱这个错误......从第二次开始,我的应用程序中的一切都运行良好......我认为问题出在我定义的商店......请帮帮我.. 。 提前致谢 ...!!!

4

2 回答 2

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'
                    }
                }
            },
于 2012-06-27T11:07:51.857 回答
0

这是真的: Object [object Object] has no methodgetRootNode 此方法在 ST2 中不再可用,请查看API 文档

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

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

removeAll: function() {
        this.getRoot().removeAll(true);
        this.callParent(arguments);
    },
于 2012-09-18T09:57:09.573 回答