无法让 webix $$("myList").refresh() 工作

Cannot get webix $$("myList").refresh() to work

我一直在努力遵循这个指南:http://developers-club.com/posts/256505/

我实在想不通为什么 $$("myList").refresh() 不起作用?我是 webix 的新手,可以使用一些帮助。

我的代码在这里: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 });
            }
    }
}

define("data", /**/) 将不起作用。对于 data loading (docs) there's another method, parse()

另外,恕我直言,一些改进会很有用

  • 在树配置中,select 是一个布尔值 属性(是的,有一个同名方法);
  • 将有助于检查物品的等级以避免不必要的重新加载
  • 你的selected变量是一个字符串,如果要使用对应的变量,查看详情at this topic
  • 如果要更改模板数据,最好直接进行,然后使用refresh()
  • 设置初始选择,有一个 ready 处理程序来捕捉树初始化的时刻

这是我建议的树配置:

  {
      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
      }
    }