简体   繁体   English

我正在尝试从操作填充子菜单,但似乎总是说未定义

[英]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.

相关问题 我正在尝试 history.push 但它在反应时总是未定义 - I am trying to history.push but its always undefined on react 因此,我试图使用for循环从数组中获取一组项目并将其显示到上下文菜单子菜单中,但是以某种方式,我无法 - So I am trying to get a set of items from an array using a for loop and displaying them into a context menu sub menu, but somehow I am not able to 我正在尝试隐藏显示菜单 <a><img></a> <a>用jQuery</a> - I am trying to hide show menu from an <a><img> with jquery 我正在尝试用对象填充div - I am trying to populate a div with an object 我正在尝试使用递增的数字填充表 - I am trying to populate a table with a number that increments 尝试从终端更改 node.js 中的环境变量,但其值始终未定义 - Trying to change the environment variable in node.js from the terminal but its value is always undefined 我正在尝试调度一个操作,但收到此错误:“未处理的拒绝(TypeError):无法读取未定义的属性'类型'” - I am trying to dispatch a action but getting this error: “ Unhandled Rejection (TypeError): Cannot read property 'type' of undefined” 我有一个菜单和一个子菜单,但是我无法访问子菜单,但是我想访问子菜单以获取适当的菜单 - I have one menu and sub menu's but I am not able to access sub menu but i want to access sub menu for appropriate menu 我正在尝试使用 JavaScript 和 Django 为页面上的不同帖子创建一个喜欢和不喜欢按钮,但它似乎只适用于第一个帖子 - I am trying to create a like and dislike button for different posts on a page using JavaScript and Django but it seems to work first post only 我正在尝试使用天气api,我正在尝试从中获取数据但未定义但属性确实存在 - I am trying to use a weather api that I am trying to pull data from i am getting undefined but the property does exist
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM