简体   繁体   English

构建后的YUI3模块更改属性

[英]YUI3 module change attribute after construction

I am building a YUI3 module for my workplace. 我正在为我的工作场所构建一个YUI3模块。 I construct it like so: 我这样构造它:

var testMenu1 = new Y.ContextMenu({
    id: 'testmenu1',
    menuItems: {
        opsdb: {
            title: 'empty',
            type: 'opsdb',
            separator: false,
            action: function(e, host) {
                iframe_panel_opsdb(host);
            }
        }
    }
});

I'd like to come in later and change the title based on the hostname I right click on. 我想稍后再输入,并根据我右键单击的主机名更改标题。 How can I do that given that testMenu1 does now exist. 鉴于testMenu1现在确实存在,我该怎么做。 I can do something like testMenu1.set('id', 'newId') but menuItems.opsdb.title, I cannot figure out how to change that one. 我可以执行类似testMenu1.set('id','newId')的操作,但可以执行menuItems.opsdb.title的操作,但我不知道如何更改该菜单。

You can access nested attributes with dot notation. 您可以使用点表示法访问嵌套属性。

Then the following should do what you want, if menuitems is an attributes. 然后,如果menuitems是属性,则以下应做您想要的。 (I do not know the details of ContextMenu). (我不知道ContextMenu的详细信息)。

testMenu1.set('menuitems.opsdb.title', 'myNewTitle'); testMenu1.set('menuitems.opsdb.title','myNewTitle');

More details there: http://yuilibrary.com/yui/docs/attribute/#subattrs 此处有更多详细信息:http: //yuilibrary.com/yui/docs/attribute/#subattrs

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM