如何在Typescript中为Cytoscape.js使用UI扩展? [英] How to use UI extension for Cytoscape.js in Typescript?

查看:267
本文介绍了如何在Typescript中为Cytoscape.js使用UI扩展?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在Typescript中使用Cytoscape UI扩展?可以使用
布局扩展名,但是当我需要例如 https://github.com时/cytoscape/cytoscape.js-cxtmenu ,我无法调用函数cy.cxtmenu(defaults),因为它不在cytoscape界面中。有没有办法使用它?

Is it possible use Cytoscape UI extensions in Typescript? Layout extension can be used but when I need for example https://github.com/cytoscape/cytoscape.js-cxtmenu, I cant call function cy.cxtmenu( defaults ) because it isnt in cytoscape interface. Is there a way to use it?

我在index.ts中的代码:

My code in index.ts:

import cytoscape = require('cytoscape');
import contextMenus = require('cytoscape-cxtmenu');
cytoscape.use(contextMenus);

const cy = cytoscape({
    container: document.getElementById('cy'),
    ...
});
let defaults = {
     menuRadius: 100, 
     selector: 'node',
    //...
};

let menu = cy.cxtmenu( defaults );

到index.d.ts我添加以下声明:

To index.d.ts I add this declare:

declare module 'cytoscape-cxtmenu' {
    const ext: cytoscape.Ext;
    export = ext;
}

在转换过程中,在控制台中,我得到以下信息:

In console during transpilation I get this:

ERROR in [at-loader] ./src/index.ts:152:17
    TS2339: Property 'cxtmenu' does not exist on type 'Core'.


推荐答案

可以使用。正如迈克尔所说,打字稿是JS的超集。您可以做JS可以做的任何事情。

Yes you can use. As Michael said typescript is super-set of JS. You can do anything that JS can do.

我正在使用其他带有角度8的上下文菜单扩展。像 import *一样,将其导入为'cytoscape-context-menus';

如果库依赖于其他js或css文件,则必须将它们添加到 angular.json 文件

If the library depends on some other js or css files, they must be added to angular.json file

这篇关于如何在Typescript中为Cytoscape.js使用UI扩展?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆