如何在ionic2打字稿中使用Timetable

如何在ionic2打字稿中使用Timetable

本文介绍了如何在ionic2打字稿中使用Timetable.js的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在ionic2项目中使用timetable.js?

Is it possible to use timetable.js in ionic2 project?

http://timetablejs.org/

我尝试如下创建timetable.d.ts.

I tried to create timetable.d.ts as belows.

declare class Timetable {
  constructor();
  scope: string;
  locations: Array<string>;
  events: Array<any>;
  setScope(start: number, end: number);
  addLocations(locations: Array<string>);
  addEvent(artistCode: string, stageCode: string, startDate: Date, endDate: Date);
  Renderer(tt: any);
}

我尝试了这三种不同的代码.

And I tried these three different code.

var renderer = Timetable.Renderer(timetable);

=>它可以正常工作,但是会发生TypeScript编译错误:类型"typeof Timetable"上不存在属性"Renderer"

=> It works correctly but TypeScript compile error occurs: Property 'Renderer' does not exist on type 'typeof Timetable'

var renderer = timetable.Renderer(timetable);

=>编译可以,但是不显示任何内容.

=> compile is ok but it doesn't display anything.

var renderer = new timetable.Renderer(timetable);

=>编译错误:只能使用'new'关键字调用void函数.它什么也不显示.

=> compile error: Only a void function can be called with the 'new' keyword. and it doesn't display anything.

我应该保留第一个代码吗?

Should I just keep 1st code?

请给我任何信息,链接或建议.

Please give me any information, link or suggestions.

谢谢.

推荐答案

您正在静态调用Renderer,这对于运行时的javascript来说不是问题,这就是为什么它仍然可以工作的原因.您可以像声明 Renderer(tt:any); 这样声明它,也可以将它作为声明的 Table 对象的方法来调用.如果时间表是已经创建的对象,则可以尝试 var renderer = new timetable.Renderer(timetable)有点奇怪,但可能会起作用.

You are calling Renderer statically, which won't be a problem for javascript at runtime, that's why it still works. You can either declare it like static Renderer(tt: any); or call it as a method of a Timetable object as you declared. If timetable is an object that you have already created, then you can try var renderer = new timetable.Renderer(timetable) which is a bit weird but might work.

这篇关于如何在ionic2打字稿中使用Timetable.js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 09:10