我正在处理一个使用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
答案 0 :(得分:0)
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;
}