【问题标题】:I'm trying to translate an example of TypeScript into JavaScript, and I'm not sure how to convert it我正在尝试将 TypeScript 的示例翻译成 JavaScript,但我不知道如何转换它
【发布时间】:2019-07-03 23:28:21
【问题描述】:

我正在处理一个使用 TypeScript 处理逻辑的 NativeScript 示例。我的工作项目使用 JavaScript,我想将示例带入我的项目。

我尝试将代码带入TS playground

import { EventData } from "tns-core-modules/data/observable";
import { Page, View } from "tns-core-modules/ui/page";
import { SwipeActionsEventData } from "nativescript-ui-listview";

import { HomeViewModel } from "./home-view-model";

export function navigatingTo(args: EventData) {
    const page = <Page>args.object;

    page.bindingContext = new HomeViewModel();
}

export function onSwipeCellStarted(args: SwipeActionsEventData) {
    const swipeLimits = args.data.swipeLimits;
    swipeLimits.left = 360;
    swipeLimits.right = 0;
    swipeLimits.threshold = 200;
}

I'm just wanting to know how it would be formated using JS

【问题讨论】:

标签: javascript xml typescript nativescript


【解决方案1】:
import { HomeViewModel } from "./home-view-model";
export function navigatingTo(args) {
    const page = args.object;
    page.bindingContext = new HomeViewModel();
}
export function onSwipeCellStarted(args) {
    const swipeLimits = args.data.swipeLimits;
    swipeLimits.left = 360;
    swipeLimits.right = 0;
    swipeLimits.threshold = 200;
}

或者如果应用程序不支持“导入”语法

const HomeViewModel = require("./home-view-model").HomeViewModel;
export function navigatingTo(args) {
    const page = args.object;
    page.bindingContext = new HomeViewModel();
}
export function onSwipeCellStarted(args) {
    const swipeLimits = args.data.swipeLimits;
    swipeLimits.left = 360;
    swipeLimits.right = 0;
    swipeLimits.threshold = 200;
}

【讨论】:

    猜你喜欢
    • 2018-11-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-23
    • 1970-01-01
    • 1970-01-01
    • 2011-01-05
    • 2022-08-17
    相关资源
    最近更新 更多