简体   繁体   English

更改 Cordova 中的加载顺序(Cordova SQLite 插件)

[英]Change Loading Order in Cordova (Cordova SQLite Plugin)

I have a Variable Reference Error in my Cordova iOS App.我的 Cordova iOS 应用程序中有一个变量引用错误。

ReferenceError: Can't find variable: db

The Variable is defined in the Plugin SQLite, but the SQLite Plugin is loading after my index.js.变量是在插件 SQLite 中定义的,但 SQLite 插件是在我的 index.js 之后加载的。 So it makes sense that it is not finding the Variable.所以它没有找到变量是有道理的。

But my Question is now: How can I change the loading order of the Plugin files or in general the loading order of the cordova files ?但我现在的问题是:如何更改插件文件的加载顺序或通常的cordova 文件的加载顺序?

First I tried to change the config.xml, I added the 'onload' parameter:首先我尝试更改 config.xml,我添加了 'onload' 参数:

<feature name="SQLitePlugin">
        <param name="ios-package" value="SQLitePlugin" />
        <param name="onload" value="true" />
</feature>

Then I tried to put my function where the Variable 'db' is used into a document.ready function, but then there was another reference error, because I called the function in my index.js before it was declared.然后我尝试将使用变量“db”的函数放入 document.ready 函数中,但随后出现了另一个引用错误,因为我在 index.js 中在声明该函数之前调用了该函数。

From some digging in the Cordova library i found that the plugins loading order is according the config.xml file declaration.通过对 Cordova 库的一些挖掘,我发现插件加载顺序是根据 config.xml 文件声明的。

In my case i wrote some custom plugins and didn't declared them in config.xml file.就我而言,我编写了一些自定义插件,但没有在 config.xml 文件中声明它们。 So i guess they was added in the build process to final config.xml file that you find in: "platforms/android/app/src/main/res/xml/config.xml" .所以我想它们是在构建过程中添加到最终 config.xml 文件中的,您可以在以下位置找到: "platforms/android/app/src/main/res/xml/config.xml"

I tried to remove the plugin i wanted to init later and add install it again, and it worked.我试图删除我想稍后初始化的插件并再次添加安装它,它起作用了。

So for the npm distributed plugins put them in wanted order in config.xml file and for your plugins install them in specific order you want.因此,对于 npm 分布式插件,请在 config.xml 文件中按所需顺序放置它们,对于您的插件,请按照所需的特定顺序安装它们。

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

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