首页 > 解决方案 > RadSideDrawer 中不再有 BindingContext 了吗?

问题描述

在 Nativescript 5.x (TypeScript) 中,我已成功使用以下代码将视图模型分配给 RadSideDrawer 的绑定上下文:

    import * as app from "@nativescript/core/application";
    import { EventData } from "@nativescript/core/data/observable";
    import { RadSideDrawer } from "nativescript-ui-sidedrawer";    

    export function drawerLoaded(args: EventData) {
        let sideDrawer = <RadSideDrawer>args.object;  <-- compiler error 1
        sideDrawer.bindingContext = new MyViewModel();
    }

然后我更新到 Nativescript 6.4、TypeScript 2.9.2、RadSideDrawer 8.0.0,然后使用“tns migrate”迁移我的应用程序。

在所有这些更新之后,我得到了一个编译器错误 1:

TS2352:将“View”类型转换为“RadSideDrawer”类型可能是一个错误,因为这两种类型都没有充分重叠。如果这是故意的,请先将表达式转换为“未知”。

SO 用户 Manoj 帮助我解决了这个问题(再次感谢您!)。我当前的代码现在看起来像这样:

export function drawerLoaded(args: EventData) {
    let sideDrawer : RadSideDrawer = <RadSideDrawer>(<any>args.object);
    sideDrawer.bindingContext = new MyViewModel(); <-- compiler error 2
}

现在我得到编译器错误2。

类型“RadSideDrawer”.ts(2339) 上不存在属性“bindingContext”

突然间 RadSideDrawer 没有绑​​定上下文了?甚至官方文档也不再提及 BindingContext 属性。这里发生了什么?

在此处输入图像描述

标签: nativescript

解决方案


推荐阅读