如何以编程方式访问页面片段自定义属性?
How to access page fragment custom properties programmatically?
如何在其中一个小部件的事件处理程序中访问页面片段的自定义属性?例如,我试图在页面片段本身的 OnLoad
事件中访问它们,如下所示:
function SumBoxOnDataLoad (widget) {
widget.descendants.TextBox.value = Currencies [widget.properties.currency]+widget.properties.value;
}
...并且 widget.properties
未定义。根据 API,即使我使用 widget.root
,它指向同一个页面片段,也没有类似的属性可以使用。
这取决于您要做什么。基本上,有两个主要用例:
- App Maker 中缺少全局可绑定变量的解决方法。 Page Fragment 本身(不是特定页面上的 Page Fragment 实例)有自己的属性,可以在整个应用程序中全局使用。此 hack/feature 在 Starter App template 中用于跟踪应用级别的菜单状态。
...
var x = app.pageFragments.MyPageFragment.properties.MyCustomProperty;
...
- 使用特定页面片段实例的属性:
// access from current page:
var x = app.currentPage.descendants.MyPageFragmentInstance.properties.MyCustomProperty;
// ...or
var x = app.pages.MyPage.descendants.MyPageFragmentInstance.properties.MyCustomProperty;
// access in page fragment instance's event (onAttach for example)
var x = widget.parent.properties.MyCustomProperty;
// access in page fragment instance descendant's event
var x = widget.root.parent.properties.MyCustomProperty;
进一步阅读:
如何在其中一个小部件的事件处理程序中访问页面片段的自定义属性?例如,我试图在页面片段本身的 OnLoad
事件中访问它们,如下所示:
function SumBoxOnDataLoad (widget) {
widget.descendants.TextBox.value = Currencies [widget.properties.currency]+widget.properties.value;
}
...并且 widget.properties
未定义。根据 API,即使我使用 widget.root
,它指向同一个页面片段,也没有类似的属性可以使用。
这取决于您要做什么。基本上,有两个主要用例:
- App Maker 中缺少全局可绑定变量的解决方法。 Page Fragment 本身(不是特定页面上的 Page Fragment 实例)有自己的属性,可以在整个应用程序中全局使用。此 hack/feature 在 Starter App template 中用于跟踪应用级别的菜单状态。
...
var x = app.pageFragments.MyPageFragment.properties.MyCustomProperty;
...
- 使用特定页面片段实例的属性:
// access from current page:
var x = app.currentPage.descendants.MyPageFragmentInstance.properties.MyCustomProperty;
// ...or
var x = app.pages.MyPage.descendants.MyPageFragmentInstance.properties.MyCustomProperty;
// access in page fragment instance's event (onAttach for example)
var x = widget.parent.properties.MyCustomProperty;
// access in page fragment instance descendant's event
var x = widget.root.parent.properties.MyCustomProperty;
进一步阅读: