编辑列引发`无法读取未定义的属性'$ sum',Webix DataTable和Firebase

时间:2017-11-12 07:06:12

标签: firebase webix

我正在尝试使用Webix DataTable来编辑Firebase上的记录,并使用Math操作计算两个记录的总和。

这是我的数据表的一部分:

view:"datatable",
id:"clientTable", 
select:true, 
multiselect:true,
editable:true, 
editaction:"click",
math: true,
footer:true,
columns:[
    { id:"index", header:"#", sort:"int", adjust:"data"},
    { id:"date", header:"Fecha", sort:"date", editor:"date", fillspace:true, adjust:"data", format:webix.Date.dateToStr("%d/%m/%y"), adjust:"data"},
    { id:"title", header:[ "Producto",{content:"textFilter"}], sort:"string", editor:"text", fillspace:true },
    { id:"bill", header: "Fractura", sort:"int", editor:"text", fillspace:true, text:"0"},
    { id:"amount", header: "Importe", sort:"int", editor:"text", fillspace:true, text:"0"},
    { id:"paid", header: "Pagado", sort:"int", editor:"text", fillspace:true, text:"0"}, 
    { id:"sum",  header:"Suma", math:"[$r,amount] - [$r,paid]"}],               //, cssFormat: mark_sum , footer:{content:"summColumn"}

rules:{

    "title": webix.rules.isNotEmpty,


    "bill": webix.rules.isNotEmpty,
    "amount": webix.rules.isNotEmpty,
    "paid": webix.rules.isNotEmpty,
    "sum": webix.rules.isNotEmpty,


    "bill": webix.rules.isNumber,
    "amount": webix.rules.isNumber,
    "paid": webix.rules.isNumber,
    "sum": webix.rules.isNumber,

    "bill": function(value){ return value > 0 },
    "amount": function(value){ return value > 0 },
    "paid": function(value){ return value >= 0 },
    "sum": function(value){ return value >= 0 }


},

在尝试修改amount列中计算的paidsum之前,一切正常。看起来我在使用Math函数进行编辑时遇到了竞争条件。

例外是:

Uncaught TypeError: Cannot read property '$sum' of undefined
    at h.jn (webix.js:1103)
    at h.jn (webix.js:1104)
    at h.gn (webix.js:1102)
    at webix.DataStore.<anonymous> (webix.js:13)
    at webix.DataStore.callEvent (webix.js:23)
    at webix.DataStore.updateItem (webix.js:524)
    at h.updateItem (webix.js:545)
    at h.ri (webix.js:790)
    at h.<anonymous> (webix.js:788)
    at h.si (webix.js:1115)

是否有任何解决方法只能在编辑后计算总和?或者避免在未定义的属性上计算这个总和?

我已尝试将默认值设置为这些列,但它根本没有帮助。

谢谢。

1 个答案:

答案 0 :(得分:0)

关于@George评论,由于firebase更改$不能用作firebase密钥的前缀,因此webix数学失败。

解决方法是使用firebase事务并自己进行数学运算。