简体   繁体   English

在黑莓级联中访问多个qml文件中的全局变量10

[英]Accessing global variable in multiple qml files in blackberry cascades 10

I have created a js file for storing constants inside assets/Model/constants.js I had a view inside assets/homeview.qml. 我创建了一个用于在assets / Model / constants.js中存储常量的js文件。我在assets / homeview.qml中有一个视图。 This homeview.qml imports 这个homeview.qml导入

import "Model/constants.js" as Global

and I could access Global.myConstant with no error. 我可以访问Global.myConstant没有错误。

Now I moved the homeview.qml inside a folder. 现在我将homeview.qml移到了一个文件夹中。 assets/Views/homeview.qml and changed the import location to assets / Views / homeview.qml并将导入位置更改为

import "/Model/constants.js" as Global

but now Global.myConstant shows unknown variable myConstant error. 但现在Global.myConstant显示未知变量myConstant错误。 Is there something else I need to do when I move file inside a folder? 当我在文件夹中移动文件时,我还需要做些什么吗?

Your import should work. 你的导入应该工作。

import "/Model/constants.js" as Global

Nevertheless, there is another way to import the file. 不过,还有另一种导入文件的方法。

import "../Model/constants.js" as Global

This is a relative path to the file. 这是文件的相对路径。 At first you go one directory up and then go into the Model directory containing the constants.js file. 首先,您进入一个目录,然后进入包含constants.js文件的Model目录。

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

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