[英]I am trying to populate sub menu from action but seems like its always saying undefined
So, I am using the vakata context menu sub menu and I am trying to create an object containing the item which I would like to display into the sub menu object. 因此,我正在使用vakata上下文菜单子菜单,并且试图创建一个包含要显示到子菜单对象中的项目的对象。 As I am calling it in the sub menu, I am always getting undefined instead of the label.
当我在子菜单中调用它时,总是会得到不确定的而不是标签。
return {
"AddClient" : {
label: "Add Client",
action: function(itemName){
var itemName, itemDisp;
itemName = 'item';
return itemDisp = {itemName : { label: 'hello'}};
},
"submenu": {
itemDisp
}
so, above I am returning the 'Add Client' as an item it the context menu, then in the action I am creating the var itemName
which is set to 'item', finally returning the `itemDisp with the item object. 因此,在上面我将上下文菜单中的“添加客户端”作为项返回,然后在操作中创建设置为“ item”的var
itemName
,最后返回带有项对象的“ itemDisp”。
After I'm calling the itemDisp
in the sub menu. 在子菜单中调用
itemDisp
之后。 As a result, this should display hello in the context menu sub menu, but instead it is always displaying undefined. 结果,这应该在上下文菜单子菜单中显示问候,但它始终显示未定义。
You declared the itemDisp
variable in your action
function and set its value in this function so the variable is scoped to this function. 您在
action
函数中声明了itemDisp
变量,并在此函数中设置了它的值,因此该变量的作用域是此函数。 If you declared also itemDisp
globally or at least in an higher scope, just remove the one in the action function. 如果还全局或至少在更高范围内声明了
itemDisp
,则只需在action函数中删除它。
Your code example is very small and do not allow me to test or reproduce anything so it is hard to help you more. 您的代码示例非常小,不允许我测试或复制任何内容,因此很难为您提供更多帮助。
If you need more help, I encourage you to add more context and make a small piece of code that reproduce your issue (on a service like codesandox, jsbin, etc) 如果您需要更多帮助,建议您添加更多上下文并编写一小段代码来重现您的问题(在诸如codeandox,jsbin等服务上)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.