【问题标题】:getStore() in ExtJS returning undefinedExtJS 中的 getStore() 返回未定义
【发布时间】:2015-11-13 08:58:49
【问题描述】:

我已经阅读了许多其他具有相同问题的帖子,但似乎没有一个能给我解决问题所需的答案。

我已将我的数据存储区定义如下:

Ext.define('TestApp.store.tbData', {
extend: 'Ext.data.Store',

alias: 'store.tbData',
storeId: 'tbData',


fields: [
    'name', 'number', 'key', 'priority'
],

data: {
    items: [
        {name: 'a', number: 'b', key: 'c', priority: 'd'}
    ]
},

proxy: {
    type: 'memory',
    reader: {
        type: 'json',
        rootProperty: 'items'
    }
}
});

那我也有我的主要观点:

Ext.define('TestApp.Templates.tbTemplate', {
extend: 'Ext.window.Window',
alias: 'tbTemplate',
itemId: 'tbWindow',

viewModel: {
    type: 'test'
},

requires: [
     'TestApp.Controllers.tbController',
     'TestApp.store.tbData',
     'TestApp.Controllers.dateTimeController'
],

controller: 'tbTemplate',

autoShow: true,
height: 600,
width: 600,
constrainHeader: true,
title: 'tb',

items: [
    {
        xtype: 'gridpanel',
        store: {
            type: 'tbData'
        },

        columns: [
            {
                xtype: 'gridcolumn',
                dataIndex: 'name',
                text: 'Name'
            },
            {
                xtype: 'gridcolumn',
                dataIndex: 'number',
                text: 'Number'
            },
            {
                xtype: 'gridcolumn',
                dataIndex: 'key',
                text: 'Key'
            },
            {
                xtype: 'gridcolumn',
                dataIndex: 'priority',
                text: 'Priority'
            }
        ]
    }
]
});

其中有一个控制器:

Ext.define('TestApp.Controllers.tbController', {
extend: 'Ext.app.ViewController',
singleton: true,

alias: 'controller.tbTemplate',

config:{stores: ['tbData'],},

requires: [
     'TestApp.store.tbData'
],

windowOpened: function () {
    console.log(Ext.getStore('tbData'));
}
});

在控制器中,当我调用 windowOpened 函数时,我试图获取数据存储区,因此最终我可以动态地向其中添加更多数据行。我可以显示我放在行中的测试数据,但我似乎无法按照我尝试的方式连接到数据存储。任何关于为什么它返回未定义以及如何解决它的帮助将不胜感激。

我已尝试使用将其添加到我的 Application.js 文件夹中

stores: ['TestApp.store.tbData']

也没有运气。

谢谢。

【问题讨论】:

  • 你试过这个吗:Ext.getStore('TestApp.store.tbData')
  • 我已经尝试了很多变体并且都返回未定义,所以我知道它只是在连接而不是返回一个值,因为它正在寻找它看起来的位置
  • 您在 Application.js 中尝试过stores: ['tbData'] 吗?
  • 另一个建议是删除(或评论)viewModel 配置和网格中的store: 'tbData',
  • 我现在得到一个错误'Uncaught TypeErrorL Cannot read property 'isBufferedStore' of undefined...我注释掉了 viewmodel 并将网格存储更改为你所说的。

标签: extjs undefined datastore extjs6


【解决方案1】:

实际上我不熟悉 extjs 6,但我阅读了您的代码,但我不明白如何将您的窗口打开事件绑定到控制器功能。所以我在小提琴上尝试了你的代码,但它不起作用。所以我读了一些关于如何绑定它的文档。这是我对您的代码所做的修改,它似乎有效。

fiddle

【讨论】:

  • 'Uncaught TypeErrorL Cannot read property 'isBufferedStore' of undefined error again,我似乎正在尝试的一切都给了我这个错误
  • 通过将其分开使其工作,然后减慢将我现有的代码添加到它的速度,到目前为止似乎工作正常,还没有遇到我以前的错误,非常感谢!
【解决方案2】:

你可以在windowOpened里面试试下面的:

var store = Ext.StoreManager.lookup('tbData');
console.log(store);

var store = this.getViewModel().getStore('tbData');
console.log(store);

【讨论】:

  • 'Uncaught TypeErrorL Cannot read property 'isBufferedStore' of undefined error again,我似乎正在尝试的一切都给了我这个错误
猜你喜欢
  • 2018-11-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-03-18
  • 2019-11-17
  • 1970-01-01
  • 2016-11-18
相关资源
最近更新 更多