如何使用webix数据映射?

时间:2016-10-04 16:07:40

标签: json datatable webix

我正在使用webix数据表。我无法映射表格的值。数据没有显示,但我知道它可以看到数据。

这是我的webix脚本和我的映射:

    webix.ajax().get('urltourltourl',{
        // Error callback
        error:function(text, data, XmlHttpRequest){
            alert("error");
        },

        //Success callback
        success:function(text, data, XmlHttpRequest){
            var data = JSON.parse(text);
            console.log(data);
        var dtable2 = webix.ui({
                container:"datatable",
                view:"datatable",
                map:{
                    1:data.data[0].centerNumber,
                    2:data.data[0].centerNumber
                },
                columns:[
                    { id:"1",   header:"CenterNBR" , width:88},
                    { id:"2",   header:"Loan NBR",  width:88},
                    { id:"3",   header:"Cust Name",     width:88},
                    { id:"4",   header:"MTD #",     width:88},
                    { id:"5",   header:"MTD $",     width:88},
                    { id:"6",   header:"MTD %",     width:88},
                    { id:"7",   header:"YTD #",     width:88},
                    { id:"8",   header:"YTD $",     width:88},
                    { id:"9",   header:"YTD %",     width:88},
                ],
                autoheight:true,
                autowidth:true,
                data: data
        }); 
        }
    });

映射应该将该ID与我从数据JSON对象中提取的值相关联,但它不会。它只是空白。

1 个答案:

答案 0 :(得分:1)

如果你想使用" map"属性,你需要

  • 将密钥更改为字母数字字符串(不是数字)
  • 将映射值写为字符串

       map:{
         "a1":"#centerNumber#",
         "a2":"#centerNumber#" 
       },
       columns:[
            { id:"a1",   header:"CenterNBR" , width:88},
            { id:"a2",   header:"Loan NBR",  width:88},
    

http://webix.com/snippet/115c1e12

如果您需要数字键,请改用scheme.init

      scheme:{
        $init:function(obj){
          obj[1] = obj.centerNumber;
          obj[1] = obj.centerNumber;
        }
      },

http://webix.com/snippet/2d1344bd