Telekrik SideDrawer问题 - 无法读取未定义的属性'showDrawer'

时间:2017-09-21 06:06:18

标签: javascript android telerik nativescript

我正在实施Telerik的SideDrawer组件并出现错误 JS:ERROR TypeError:无法读取属性' showDrawer'未定义。 我正在使用本教程 https://www.nativescript.org/blog/a-deep-dive-into-telerik-ui-for-nativescripts-sidedrawer

我的XML是,

<Page xmlns:lv="nativescript-telerik-ui/listview" xmlns:sd="nativescript-telerik-ui/sidedrawer" loaded="pageLoaded" unloaded="pageUnloaded" xmlns="http://www.nativescript.org/tns.xsd" navigatedTo="onNavigatedTo">            <ActionBar title="RadSideDrawer Demo" class="action-bar" >
    <ActionItem tap="toggleDrawer" ios.systemIcon="4" android.systemIcon="ic_menu_btn_add" ios.position="left" />
</ActionBar>
        <sd:RadSideDrawer id="sideDrawer" drawerLocation="Left">    
            <!-- side drawer content -->
            <sd:RadSideDrawer.drawerContent>
                <StackLayout class="sidedrawer-left">
                    <StackLayout class="sidedrawer-header">
                        <Label text="Hello RadSideDrawer!" class="sidedrawer-header-brand" />
                    </StackLayout>
                    <StackLayout class="sidedrawer-content">
                        <Label text="Home" class="sidedrawer-list-item-text" />
                        <Label text="Basics" class="sidedrawer-list-item-text" />
                        <Label text="Options" class="sidedrawer-list-item-text" />
                        <Label text="Help" class="sidedrawer-list-item-text" />
                        <Label text="Advanced" class="sidedrawer-list-item-text" />
                    </StackLayout>
                </StackLayout>
            </sd:RadSideDrawer.drawerContent>

            <!-- The main content -->


        </sd:RadSideDrawer>

和javascript文件是

var view = require("ui/core/view");
var drawer="";
exports.toggleDrawer = function() {

    drawer.showDrawer();
};
exports.onNavigatedTo = function() {
    drawer = view.getViewById(page, "sideDrawer");
};

使用最新版本tns-android,tns-core-mocules,telekriki-ui ... 我错过了什么?任何帮助将不胜感激..

2 个答案:

答案 0 :(得分:0)

我也有这个问题;在以前的版本中没有发生过;它适用于ios;只有android遇到麻烦。 如果第一次执行,则没有错误,并且sidedrawer具有该值。 但是在第二次运行中,它会返回一个错误并返回&#34; undefined&#34;

答案 1 :(得分:0)

在执行getViewById()

之前,您需要获取对该页面的引用

所以你的onNavigatingTo看起来像

exports.onNavigatedTo = function(args) {
    const page = args.object;
    drawer = page.getViewById(page, "sideDrawer");
};