2

我正在使用 Telerik ui 作为本机脚本。我需要顶部的切换按钮来打开侧面菜单。但我无法Showdrawer()按照文档调用。我需要的是按钮单击侧菜单应该打开。我试过打电话 RadSideDrawer.prototype.showDrawer(),但失败了。还有其他可用的侧菜单Nativescript吗?

主页.xml

<Page xmlns="http://www.nativescript.org/tns.xsd" xmlns:drawer="nativescript-telerik-ui/sidedrawer" loaded="pageLoaded">
    <Page.actionBar>
        <ActionBar>
            <android>
                <NavigationButton text="Go Back" android.systemIcon="ic_menu_moreoverflow" tap="showSideDrawer" />
            </android>
        </ActionBar>
    </Page.actionBar>
    <drawer:RadSideDrawer>
        <drawer:RadSideDrawer.mainContent>
            <StackLayout>
                <Label text="{{ mainContentText }}" textWrap="true" />
            </StackLayout>
        </drawer:RadSideDrawer.mainContent>
        <drawer:RadSideDrawer.drawerContent>
            <StackLayout cssClass="drawerContent" style="background-color:white;">
                <StackLayout cssClass="headerContent">
                    <Label text="Header" />
                </StackLayout>
                <StackLayout cssClass="drawerMenuContent">
                    <Label text="Item 1" style="color:black;" />
                    <Label text="Item 2" style="color:black;" />
                    <Label text="Item 3" style="color:black;" />
                    <Label text="Item 4" style="color:black;" />
                </StackLayout>
            </StackLayout>
        </drawer:RadSideDrawer.drawerContent>
    </drawer:RadSideDrawer>
</Page>

入门-model.js

var observableModule = require("data/observable");
var GettingStartedViewModel = (function (_super) {
    __extends(GettingStartedViewModel, _super);
    function GettingStartedViewModel() {
        _super.call(this);
        this.set("mainContentText", "SideDrawer for NativeScript can be easily setup in the XML definition of your page by defining main- and drawer-content. The component"
            + " has a default transition and position and also exposes notifications related to changes in its state.");

    }
    return GettingStartedViewModel;
})(observableModule.Observable);
exports.GettingStartedViewModel = GettingStartedViewModel;
function showSideDrawer(args) {
    console.log("Show SideDrawer tapped.");
    // Show sidedrawer ...
   _super.prototype.showDrawer.call(this);

}
exports.showSideDrawer = showSideDrawer;

主页.js

var viewModelModule = require("./getting-started-model");
function pageLoaded(args) {
    console.log("Page loaded");
    var page = args.object;
    page.bindingContext = new viewModelModule.GettingStartedViewModel();
}
exports.pageLoaded = pageLoaded;
4

4 回答 4

2

您可以查看显示 RadSideDrawer 主要功能的SDK 示例。正如@R Pelzer 所提到的,您需要做的就是获取 RadSideDrawer 的实例,例如使用它的 id:

import drawerModule = require("nativescript-telerik-ui-pro/sidedrawer");
import frameModule = require("ui/frame");

var sideDrawer: drawerModule.RadSideDrawer = <drawerModule.RadSideDrawer>(frameModule.topmost().getViewById("sideDrawer"));

并调用它的showDrawer()方法:

sideDrawer.showDrawer();
于 2016-05-08T10:09:19.280 回答
1

您是从未发布的代码中调用 showSideDrawer 函数吗?你确定你链接了点击按钮吗?

<Button tap="showSideDrawer" text="ToggleDrawer"/>

也许您可以尝试给 sideDrawer 一个 Id 并使用此代码。

var drawer = frameModule.topmost().getViewById("sideDrawer");
drawer.showDrawer();
于 2016-05-06T11:12:43.103 回答
1

您得到的undefined原因是没有为抽屉分配 ID,因此要解决您的问题,请为 sideDrawer 分配一个 ID,<drawer:RadSideDrawer id="sideDrawer"> 然后您可以调用

var frame = require('ui/frame');
var drawer = frame.topmost().getViewById("sideDrawer");

function showSideDrawer(){
drawer.showDrawer();  // i prefer using .toggleDrawerState();
};
于 2016-05-09T13:30:59.153 回答
0

就我而言,我错过了插入,因此,在调用 toggleDrawer 时缺少一个组件,因此出现错误“TypeError:无法读取未定义的属性 'toggleDrawerState'”。

尝试在其中插入 xml 文件的所有正文组件可能会解决问题。

快乐编码:))

于 2018-04-09T07:50:24.450 回答