【问题标题】:extjs 4Uncaught TypeError: Cannot read property 'items' of undefinedextjs 4Uncaught TypeError:无法读取未定义的属性“项目”
【发布时间】:2017-12-13 17:15:59
【问题描述】:

我想通过示例数据加载带有商店和模型的图表。但是加载数据时出现错误:无法读取未定义的属性“项目” 我在控制器中创建商店和模型并设置图表值:

var chart = Ext.create('Ext.chart.Chart', {
                    animate: true,
                    store: Ext.create('Ext.data.Store', {
                        model: Ext.create('Ext.data.Model', {
                                fields: ['temperature', 'date']
                            }
                        ),
                        data: [
                            {temperature: 58, date: new Date(2011, 1, 1, 8)},
                            {temperature: 63, date: new Date(2011, 1, 1, 9)},
                            {temperature: 73, date: new Date(2011, 1, 1, 10)},
                            {temperature: 78, date: new Date(2011, 1, 1, 11)},
                            {temperature: 81, date: new Date(2011, 1, 1, 12)}
                        ]
                    }),
                    axes: [{
                        type: 'numeric',
                        position: 'left',
                        title: 'y',
                        minimum: 0
                    },
                        {
                            type: 'date',
                            position: 'bottom',
                            title: 'x',
                            minimum: 0
                        }],
                    series: [{
                        type: 'column',
                        axis: 'left',
                        highlight: true,
                        tips: {
                            trackMouse: true,
                            width: 140,
                            height: 28
                        }
                    },
                        {
                            label: {
                                display: 'insideEnd',
                                'text-anchor': 'middle',
                                renderer: Ext.util.Format.numberRenderer('0'),
                                orientation: 'vertical',
                                color: '#333'
                            },
                        }
                    ],
                });

我想将此图表添加到面板

Ext.ComponentQuery.query('panel')[0].add(chart);

【问题讨论】:

    标签: extjs charts model store


    【解决方案1】:

    无法读取未定义的属性“项目”,因为您正在直接创建模型实例而没有定义。

    这是小提琴http://jsfiddle.net/djaydxnd/66/

     store: Ext.create('Ext.data.Store', {
           model:Ext.define('chart', {
               extend: 'Ext.data.Model',
               fields: ['temperature','date']
           }),                      
           data: [
                                      {temperature: 58, date: new Date(2011, 1, 1, 8)},
                                    {temperature: 63, date: new Date(2011, 1, 1, 9)},
                                    {temperature: 73, date: new Date(2011, 1, 1, 10)},
                                    {temperature: 78, date: new Date(2011, 1, 1, 11)},
                                    {temperature: 81, date: new Date(2011, 1, 1, 12)}
    
          ]
         })
    

    【讨论】:

    • 回答问题
    猜你喜欢
    • 1970-01-01
    • 2021-04-12
    • 1970-01-01
    • 1970-01-01
    • 2021-09-08
    • 1970-01-01
    • 2017-12-15
    • 1970-01-01
    • 2020-11-29
    相关资源
    最近更新 更多