gpt4 book ai didi

javascript - jQuery 中的上下文菜单项

转载 作者:行者123 更新时间:2023-12-03 04:50:09 25 4
gpt4 key购买 nike

我想通过 jQuery 显示条件上下文菜单项。

例如:

我的帐户中有汽车。我想展示有条件的选项。

如果汽车是我自己的,那么所有菜单项都应该对我可见。如果与我共享,则只有“查看菜单”对我可见。

if (type == 'vehicle') {
(function () {
var vehicle_id = node.data.vehicle_id;
var vehicle_status = '';
$.ajax({
url: baseUrl + '/check-vehicle-status/'+vehicle_id,
success: function(data) {
console.log(data);
if(data == 'shared'){
//what should I write here? to show only View option
}
}
});

items = {
"View": {
"label": "View Vehicle",
"action": function action() {
self.viewVehicle(vehicle_id);
}
},
"modify": {
"label": "Edit Vehicle",
"action": function action() {
self.editVehicle(vehicle_id);
}
},
"delete": {
"label": "Delete Vehicle",
"action": function action() {
dialogHandler.showDeleteVehicle(function () {
self.removeVehicle(vehicle_id);
});
}
},

最佳答案

您必须在上下文菜单方法中检查 data 参数,如下所示(前提是树节点的 node.data 具有值)。

查看演示 - Fiddle Demo

...
contextmenu: {
items: function (node) {

// remove default context menu items
var tmp = $.jstree.defaults.contextmenu.items();
delete tmp.rename;
delete tmp.remove;
delete tmp.ccp;
delete tmp.create;

for (menuItem in items) {
if( menuItem === 'View' || node.data !== 'shared') {
tmp[ menuItem ] = {
id: menuItem,
label: items[menuItem].label,
action: items[menuItem].action
}
}
}

return tmp;
}
},

关于javascript - jQuery 中的上下文菜单项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42691989/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com