When sidebar closed, subitems value and/or filter maintain old value.

Hi,

In my site, i have a sidebar menu.

In ready of sidebar i need change the text of every item. and i use this code:

...
view:"sidebar",
ready:function(){

$$("menu").filter(function (obj) { 
                         
    if (obj.value === "INITIAL TEXT 1_1") 
      return false;
    else
      return true;
 });

 $$("menu").data.each( function (obj) {
           var nodeObj = $$("menu").getItem(obj.id);
           var nodeObjCurrentValue = nodeObj.value;
           nodeObj.value = "CHANGE TEXT";
     }
 );
}

When menu is open, show correct text en every item, but when i toggle the sidebar , subitems maintain “old text”

Please check this snippet ,

https://snippet.webix.com/2rdtf7dd

values in data are:

INITIAL TEXT
…INITIAL TEXT_1_1
…INITIAL TEXT_1_2

is OK,

In ready of sidebar menu change items value to “CHANGE TEXT” and filter where value != “INITIAL TEXT_1_1” then show

CHANGE TEXT
…CHANGE TEXT

is OK

When click in button toogle and check sidebar menu subitems , show:

CHANGE TEXT
…INITIAL TEXT_1_1
…INITIAL TEXT_1_2

is NOT OK :frowning:

Is a bug or i need to do something more to change text in a sidebar menu?.

Thanks in advance.

Hello,

It’s a limitation of the Sidebar widget, which doesn’t share the same data for the main Tree and popup Menu.

To modify menu items, you will have to deal with data within the menu array of the related parent items:

 $$("menu").data.each(  function (obj) {
   if(obj.menu){
      obj.menu.splice(0, 1); //remove item
      obj.menu[1].value = "Changed menu"; //change item text
   }
});

Also, as popup data is parsed to it each time when it is shown, you can alter it by handling the onShow event:

$$("menu").getPopup().attachEvent("onShow", function(){...});

Please, check the related snippet: Code Snippet

Thanks Helga!!!