在app.js中设置一个具有函数的商店不能在生产构建中工作吗?

时间:2014-03-04 15:00:57

标签: extjs build touch store production

我正在尝试根据以下Sencha示例创建搜索表单视图: http://try.sencha.com/touch/2.0.0/examples/list-search/viewer.html

我做了一些更改,只是不按代码创建视图,而是将其导出到视图中。

要设置商店,我在配置中使用它:

store:Preconisations.app.getStoreAdherents(),

其中Preconisations是我的项目名称,getStoreAdherents是在app.js中设置的函数:

getStoreAdherents: function () {
    if (!this.storeAdherents) {
        var gestionAdherent = new DAL_Adherent(); // custom classes 
        var tc = gestionAdherent.GetAll(); // and functions which returns a json string with data

        this.storeAdherents = Ext.create('Ext.data.Store', {
            model: "Preconisations.model.ADHERENT",
            data: tc,
            sorters: 'nom',
            groupField: 'code'
        });
    }

    return this.storeAdherents;
}

现在,一切正常,但是当我进行测试或生成构建时,我遇到了这个错误:

未捕获的TypeError:无法调用未定义的方法'getStoreAdherents'

在商店定义......

也许,有一种更好的方法来通过代码设置商店,但我无法理解为什么它在开发中工作而不是生产或测试版本......

有人有这个问题吗?或者,如何使用函数动态设置商店?

谢谢......我在这个墙上敲我的头......

2 个答案:

答案 0 :(得分:0)

很明显,Ext Build中存在构建依赖性问题。在发布的代码段中,您可能错过了将“Preconisations.model.ADHERENT”添加到类路径中。如果是这样,请将以下内容添加到您的app.js

requires: ["Preconisations.model.ADHERENT"]

如果问题仍然存在,请执行以下诊断:    在控制台打开的情况下在Google Chrome中运行您的应用(开发模式);查找声明正在同步加载特定类的警告,并为这些类添加require语句。

答案 1 :(得分:0)

事实上,我认为在配置中动态设置商店存在一个错误。 我发现这种解决方法适用于开发和构建生产:

我没有在视图中指定商店: xxxx 。 相反,在控制器中,我将此代码放在启动函数中:

this.getMainView()。setStore(this.getStoreAdherents());

其中getMainView是对我视图的引用。

这就是全部!