在 Symbian/QML 应用程序中的屏幕之间传递状态
我正在尝试使用 Loader
加载全屏组件以更改 Symbian/QML 项目中的屏幕。这感觉不是正确的方法,所以我可能错过了一些明显的东西。
我将使用的示例是一个屏幕上的按钮,该按钮应打开全屏 WebView(又名 ChildBrowser)。我想让 ChildBrowser 成为一个可重用的组件,因此需要将 URL 传递给它。
我尝试使用pragma library
构建一个Javascript文件:
.pragma library
var map = {};
function put(key, value) {
map[key] = value;
}
function get(key) {
return map[key];
}
由于需要更好的标题,我们称之为intent.js
。
按住按钮的屏幕:
import "intent.js" as Intent
Button {
onButtonClicked: {
Intent.put("url", "http://example.com");
console.log("Going to " + Intent.get("url"));
}
}
稍后,在 ChildBrowser.qml
中,我导入“intent.js”,然后获取 Intent.get(“url”)。这是未定义
。
我的问题是:
- 使用
Loader
是在屏幕之间构建和转换的预期方式吗? - 如何在屏幕之间传递参数?
- 如何在应用程序的整个生命周期中维护状态?我对用 Javascript 构建控制器和模型特别感兴趣。
我确信这些都是新手问题,因此可能只需要一组相关文档的链接即可;但我怀疑不会。
I'm trying to use a Loader
to load full screen components to changing screens in a Symbian/QML project. This doesn't feel like the correct way to do it, so I'm probably missing something obvious.
The example I'll use is a button on one screen which should open a full screen WebView (a.k.a ChildBrowser). I'd like to make the ChildBrowser a re-usable component, so need to pass the URL to it.
I've tried building a Javascript file with a pragma library
:
.pragma library
var map = {};
function put(key, value) {
map[key] = value;
}
function get(key) {
return map[key];
}
For want of a better title, we call this intent.js
.
The screen holding the button:
import "intent.js" as Intent
Button {
onButtonClicked: {
Intent.put("url", "http://example.com");
console.log("Going to " + Intent.get("url"));
}
}
Later on, in ChildBrowser.qml
, I'm importing "intent.js" and then getting the Intent.get("url"). This is undefined
.
My questions are:
- is using a
Loader
the intended way to build and transition between screens? - how do you pass parameters between screens?
- how do you maintain state across the lifetime of the app? I'm especially interested in building controllers and models in Javascript.
I'm sure these are newbie questions, so a set of links to the relevant documentation is probably all that is needed; I suspect not however.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
加载器是避免创建项目直到您需要它们的好方法。
假设 ChildBrowser 有一个“url”属性,您可以执行以下操作:
向您的 ChildBrowser 添加“url”属性只需在根项上拥有一个属性即可,例如
Loader is a good way to avoid creating items until you need them.
Assuming ChildBrowser has a "url" property, you could do something like this:
Adding a "url" property to your ChildBrowser is simply a matter of having a property on the root item, e.g.