TypeScript 中的 JsTree 自定义上下文菜单
JsTree custom contextmenu in TypeScript
我尝试在 angularjs 应用程序的 TypeScript 代码中使用 jstree 控件。我使用 jstree 类型和 jstree.directive 来显示一棵树。当我需要处理菜单项单击并调用基本方法时,一切正常。在我的操作中,没有 "this" (contextmenu) 作用域。有什么建议么?
class MapTreeViewController {
mapTreeView: JSTree;
vm.mapTreeView = $('#jstree').jstree(
{
'core': { 'data': items },
'plugins': ['themes', 'ui', 'contextmenu'],
'contextmenu': {
'items': function(node:any) {
var vmNode = this;
return {
'rename': { // rename menu item
'label': 'Rename',
'action': function(obj) {
this.rename(obj);
}
}
};
}
}
});
}
方法内部的某处。
this
不是实例 - 查看原始函数以了解如何获取实例:
https://github.com/vakata/jstree/blob/master/src/jstree.contextmenu.js#L84
"action" : function (data) {
var inst = $.jstree.reference(data.reference),
...
我尝试在 angularjs 应用程序的 TypeScript 代码中使用 jstree 控件。我使用 jstree 类型和 jstree.directive 来显示一棵树。当我需要处理菜单项单击并调用基本方法时,一切正常。在我的操作中,没有 "this" (contextmenu) 作用域。有什么建议么?
class MapTreeViewController {
mapTreeView: JSTree;
vm.mapTreeView = $('#jstree').jstree(
{
'core': { 'data': items },
'plugins': ['themes', 'ui', 'contextmenu'],
'contextmenu': {
'items': function(node:any) {
var vmNode = this;
return {
'rename': { // rename menu item
'label': 'Rename',
'action': function(obj) {
this.rename(obj);
}
}
};
}
}
});
}
方法内部的某处。
this
不是实例 - 查看原始函数以了解如何获取实例:
https://github.com/vakata/jstree/blob/master/src/jstree.contextmenu.js#L84
"action" : function (data) {
var inst = $.jstree.reference(data.reference),
...