0

I have been trying to follow this guide: http://developers-club.com/posts/256505/

I simply cannot figure out why the $$("myList").refresh() is not working ? Am a complete newbie to webix and can use some help please.

my code is here: http://sahanaya.net/webix/webix2.html

{view:"tree", id:"myTree", data:recordsData, select: oceanData, on: {
    onSelectChange: function(){
        selected = $$("myTree").getSelectedId();
            if (isNaN(selected)) {
                $$("myList").clearAll();
                $$("myList").define("data", selected);
                $$("myList").refresh(); <-- THIS DOES NOT WORK ??
                coverPath = "imgs/" + selected + ".jpg"
                $$("myCover").define("data", { src: coverPath });
            }
    }
}

1 Answers1

1

define("data", /**/) will not work. For data loading (docs) there's another method, parse()

Also, some improvements will be useful IMHO

  • in tree config, select is a boolean property (and yep, there's a same-name method);
  • will be useful to check item's level to avoid the unnecessary reloading
  • your selected variable is a string, and if you want to use the corresponding variable, check the details at this topic.
  • if you want to change the template data, better to do it directly and then use refresh()
  • to set the initial selection, there's a ready handler to catch the moment when the tree is initialized

Here's the tree config I suggest:

  {
      view:"tree",
      id:"myTree", 
      data:recordsData, 
      select: true,  // boolean property.
      on: {
        onSelectChange: function(){             
          selected = $$("myTree").getSelectedId();            
          if (isNaN(selected)) {              
            var selectedItem = $$("myTree").getItem(selected);                          
            if (selectedItem.$level == 2){ // checks whether it's the 'album' level
              $$("myList").clearAll();
              $$("myList").parse(window[selected]); // instead of `define`+`refresh`
              // note that string ID isn't the variable name, but window[selected] can handle the global variable
              coverPath = "imgs/" + selected + ".jpg";
              // but `refresh` is required for ui.template:
              $$("myCover").data.title = coverPath;
              $$("myCover").refresh(); 
            }
          }
        }            
      },
      ready:function(){
        this.open("1");
        this.select("oceanData") // therefore, initial var selected can be an empty array
      }
    }
Community
  • 1
  • 1
Loj
  • 437
  • 2
  • 11
  • Thank you Loji like I said total newbie here. Let me try to 'understand' what you have explained first then will be back with more questions :-) – Aruna Hewapathirane Oct 12 '16 at 13:27
  • You're welcome! Actually, that article is weird (or just outdated). As far as I know Webix, defining the data shouldn't work at all – Loj Oct 12 '16 at 13:37
  • Hey Loj, I tested your code and it works so I am accepting this as the correct answer. I am yet to fully understand things though but am highly impressed with what the webix folks have done and they have a GPL version as well. If you have any tutorials please do send me some links. Thanks very much once again. – Aruna Hewapathirane Oct 12 '16 at 13:48
  • Well, I prefer an empirical evaluating process, i.e. samples-docs-forum. Unfortunately, I can't remember any noticeable tutorials outside their site, but for the start, these are quite good http://docs.webix.com/desktop__getting_started.html – Loj Oct 12 '16 at 15:17
  • Loj could you please have a look here: [http://sahanaya.net/webix/flags3.html] I can't get the row data when clicked. Trying to display related data in another row when datatable is clicked and header is not working as well. Thanks. – Aruna Hewapathirane Oct 15 '16 at 13:54
  • sorry that's : http://sahanaya.net/webix/flags3.html and when row clicked want to grab the data and display other related data in bottom row yet to be worked in :) – Aruna Hewapathirane Oct 15 '16 at 13:56
  • Oh, sorry, I wasn't here these days, but I've answered your remaining question in another topic. – Loj Oct 21 '16 at 12:48