Platypi 中 ViewControl 的注册函数放在哪里

Where to place register function for ViewControl in Platypi

我一直在浏览 [Platypi.io/docs/getting-started/][1],但卡在了有关添加功能以允许用户注册演示应用程序的部分 (https://platypi.io/docs/getting-started/allow-users-to-register)

具体步骤是

Now, let's add our register function. This function will be fired whenever the plat-button is tapped or clicked. In the template, we defined our button's tap event by specifying a function in the plat-tap attribute. The function name is register, so when that button is clicked, the register function will be fired on our ViewControl. Add the register function to the view control (in public/viewcontrols/register/register.viewcontrol.ts:

register() {
    this.context.error = '';
    this.userRepository.register(this.context.email,
        this.context.password,
        this.context.firstname,
        this.context.lastname)
    .then((success) => {
        this.navigator.navigate(HomeViewControl);
    }).catch((error) => {
        this.context.error = error;
    });
}

在哪里添加这个功能?如果我把它放在 RegisterViewControl 中(如 [this][2])class,我会得到这个错误:error TS2094: The property 'navigator' does not exist on value of type 'RegisterViewControl'. this.navigator.navigate(HomeViewControl); 在 class 之外,语法不起作用。

我知道自己的方法 Javascript,但我是 TypeScript 的新手。有什么建议吗?

您的 RegisterViewControl 应该扩展 BaseViewControl,并且在某种程度上它应该扩展 plat.ui.ViewControlplat.ui.ViewControl 上有一个名为 navigator 的 属性。从您的错误来看, RegisterViewControl 的定义方式似乎有问题。

如果上述解决方案不起作用,您能否提供整个 RegisterViewControl 文件的代码?

编辑:看起来您确实是正确的。声明 .d.ts 文件可能有问题。尝试删除 .tscache 文件夹,然后再次 运行 npm install。它可能会给您带来更多有用的错误。

我们最近(和昨天一样)更新了框架和 UI 项目以部署不同的结构。您的 public/typings/tsd.d.ts 中可能有以下参考资料:

/// <reference path="../../node_modules/platypus/platypus.d.ts" />
/// <reference path="../../node_modules/platypusui/platypusui.d.ts" />

仔细检查 node_modules 目录,您可能需要将 tsd.d.ts 更改为以下内容:

/// <reference path="../../node_modules/platypus/dist/platypus.d.ts" />
/// <reference path="../../node_modules/platypusui/dist/platypusui.d.ts" />

如果是这种情况,您还应该进入 public/common/css/main.less 文件并更改此行:

@import "../../../node_modules/platypusui/platypus";

对此:

@import "../../../node_modules/platypusui/dist/platypus";