简体   繁体   English

extjs4网格简单示例,但错误:未定义的“项目”

[英]extjs4 grid simple example but an error: 'items' of undefined

I have been practicing to make a really simple grid example on JSFiddle, I've stuck in this problem. 我一直在尝试在JSFiddle上做一个非常简单的网格示例,但我一直陷在这个问题中。

I have 1 model, 1 store, and 1 grid object. 我有1个模型,1个商店和1个网格对象。 I think I put everything properly into appropriate spaces, but all I got from the result was 'Cannot read property "items" of undefined', can anyone please explain why this happens to me, please? 我认为我已将所有内容正确放置在适当的位置,但从结果中得到的只是“无法读取未定义的属性“项目””,任何人都可以解释一下为什么会发生在我身上吗?

 var model = Ext.create('Ext.data.Model', { fields: [ {name: 'name', type: 'string'}, {name: 'value', type: 'float'} ] }); var store = Ext.create('Ext.data.Store', { model: model, data: [ {name: 'a', value: 1.2}, {name: 'b', value: 2.3}, {name: 'c', value: 3.4}, {name: 'd', value: 4.5}, ] }); Ext.create('Ext.grid.Panel', { width: 500, height: 500, store: store, columns: [ {text: 'header', dataIndex: 'name'}, {text: 'header2', dataIndex: 'value'} ], renderTo: Ext.getBody() }) 

'Create' creates an instance of the parent element.Hence need to define model,before creating instances of it. '创建'创建父元素的实例。因此需要在创建模型之前定义模型。

Ext.define('occupationModel', {
    extend: 'Ext.data.Model',

    fields: [
        {name: 'code', type: 'int'},
        {name: 'occup', type: 'string'}
    ]
});

Ext.create('occupationModel', {
    code : 1,
    occup : 'foo'
});

If you are using JSFiddle then you need to include ExtJS all required libraries like 如果您使用的是JSFiddle,则需要包括ExtJS所有必需的库,例如

  1. ext-all-debug.js as per depend on your requirement you can change version of ExtJS library. 根据您的要求, ext-all-debug.js可以更改ExtJS库的版本。
  2. ext-theme-neptune only for theme what you want to use you can change. ext-theme-neptune仅适用于您想要使用的主题,您可以更改。
  3. ext-theme-neptune-all-debug only for theme what you want to use you can change. ext-theme-neptune-all-debug仅适用于您要使用的主题,可以更改。

Here in JSFiddle I have created an demo you check here how it is working. JSFiddle中,我创建了一个演示,您可以在此处查看其工作方式。 Hope this will help you. 希望这会帮助你。

Ext.create('Ext.data.Store', {
    storeId:'simpsonsStore',
    fields:['name', 'email', 'phone'],
    data:{'items':[
        { 'name': 'Lisa',  "email":"lisa@simpsons.com",  "phone":"555-111-1224"  },
        { 'name': 'Bart',  "email":"bart@simpsons.com",  "phone":"555-222-1234" },
        { 'name': 'Homer', "email":"homer@simpsons.com",  "phone":"555-222-1244"  },
        { 'name': 'Marge', "email":"marge@simpsons.com", "phone":"555-222-1254"  }
    ]},
    proxy: {
        type: 'memory',
        reader: {
            type: 'json',
            rootProperty: 'items'
        }
    }
});

Ext.create('Ext.grid.Panel', {
    title: 'Simpsons',
    store: Ext.data.StoreManager.lookup('simpsonsStore'),
    columns: [
        { text: 'Name',  dataIndex: 'name' },
        { text: 'Email', dataIndex: 'email', flex: 1 },
        { text: 'Phone', dataIndex: 'phone' }
    ],
    height: 200,
    width: '100%',
    renderTo: Ext.getBody()
});

You can also check here working Sencha Fiddle . 您也可以在这里检查Sencha Fiddle

Solution for your problem is to change your model with below code. 解决您的问题的方法是使用以下代码更改模型。

 Ext.define('model', { extend: 'Ext.data.Model', fields: [ {name: 'name', type: 'string'}, {name: 'value', type: 'float'} ] }); 

Also, click on link to know more about, Differences between Ext.create() and Ext.define() 另外,单击链接以了解更多有关Ext.create()和Ext.define()之间的区别的信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM