Uncaught typeError: Cannot read property 'isModel' of undefined

问题描述 投票:0回答:2

嗨,我在执行我的代码后收到此错误。它说“未捕获的类型错误:无法读取未定义的属性'isModel'”。我正在尝试使用我定义的名为“model.login”的模型和带有虚拟数据的商店来显示列表。

Ext.Loader.setConfig({
enabled: true,
paths:{
    'model' : 'app/model',
    'store' : 'app/store'
}

});
Ext.application({
    name: 'GS',
    launch: function(){
        var myStore = null;
        Ext.require('model.login', function(){
            var login = Ext.create('model.login');
            myStore = new Ext.data.Store({
                model: login,
                data:[
                      {id:'09803' , issued_at: 'thisurl', instance_url:'https', signature:'token', access_token:'ser'}
                      ]
            });
        });
        this.viewport = new Ext.Panel({
            fullscreen: true,
            items:[
                   {
                       xtype: 'list',
                       itemTpl: '{id}',
                       store: myStore
                   }
                   ]
        });
    }

});
sencha-touch
2个回答
2
投票

您创建视口的调用发生在

model.login
加载和您的商店创建之前。将创建视口的代码移动到
Ext.require
.

的回调中

此外,当将模型传递到商店时,您传递的是模型构造函数,而不是它的实例。

Ext.application({
  name: 'GS',
  launch: function(){
    this.viewport = 
    var me = this;
    Ext.require('model.login', function(){                
      myStore = new Ext.data.Store({;

      me.viewport = new Ext.Panel({
        fullscreen: true,
        // You can pass a single item into item
        items:{
          xtype: 'list',
          itemTpl: '{id}',
          store: myStore
        }
      });
    });
  }
});

请注意,有更好的方法可以做到这一点,您可以告诉应用程序要加载哪些模型并内联您的一些调用以使其更易于阅读

Ext.application({
  name: 'GS',
  models: 'login', // looks in GS.model.login
  launch: function(){
    me.viewport = new Ext.Panel({
      fullscreen: true,
      // You can pass a single item into item
      items:{
        xtype: 'list',
        itemTpl: '{id}',
        store: {
          model: 'model.login', // or GS.model.login without quotes
          data:[              
            {id:'09803' , issued_at: 'thisurl', instance_url:'https', signature:'token', access_token:'ser'}]
          }
       }
    });
  }
});

0
投票

对我来说,它在 sql 中被错误命名为列。

© www.soinside.com 2019 - 2024. All rights reserved.