EXTJS:未捕获的ReferenceError:dexie未在myJavascriptFile.js中定义:18

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

我正在为另一个(Dexie)换掉一个IndexedDb包装器(localForage),我无法运行该应用程序,因为在ExtJs框架中集成它的推荐方法对我不起作用。我做错了什么?

我目前的ExtJs版本:框架:6.6.0.258 Cmd:v6.6.0.13 Dexie版本是最新版本

Dexie文档建议您像这样设置数据库

 var db = new Dexie("MyDatabase");
     db.version(1).stores({
        myStoreName, "++id, indexOne, indexTwo",
        myOtherStoreName, "++id, indexOne, indexTwo",
     });

myExtJsFile.js

   Ext.define('DataLayer.Inferface', {
      extend: 'Ext.Component',
      xtype: 'DLInterface',
      config: {
          stuff...
        db: new Dexie("mydatabaseName"),
      }

ExtJs文档建议使用外部库的方式是在js数组中的app.json文件中引用它

app.json

"js": [
   {
     "path": "${framework.dir}/build/ext-all-rtl-debug.js"
   },
   {
     "path": "dexie.js"     //Dexie is located in the same folder as app.json
   },

我得到一个成功的构建但是当我去部署它(在本地运行)时,我得到了这个问题标题中列出的运行时错误。我知道VSCode中的intellisense并没有那么好用,所以当我没有出现访问全局Dexie对象时,我并没有真正想到它。我尝试了几种不同的方法,加载这个库的地方m =没有运气。我会使用CDN,但它是一个离线功能的应用程序,所以我真的想在本地库。我应该如何在Ext中获取,引用和使用第三方库?

谢谢。

extjs local-storage indexeddb dexie
1个回答
0
投票

如果在Ext.define中使用外部库,请尝试在extjs库(ext-all-rtl-debug.jsapp.js等)之前包含外部库。

另一个解决方案 - 不要在类定义上附加远程库 - 而是使用initialize / initComponent。例:

Ext.define('DataLayer.Inferface', {
extend: 'Ext.Component',
xtype: 'DLInterface',
config: {
    stuff...
},
initComponent: function () {
    this.db=new Dexie("mydatabaseName");
    this.callParent(arguments);
}
© www.soinside.com 2019 - 2024. All rights reserved.