firebase - 编辑列引发 `Cannot read property ' $sum' of undefined`、Webix DataTable 和 Firebase

标签 firebase webix

我正在尝试使用 Webix DataTable 来编辑 Firebase 上的记录并使用数学运算计算两条记录的总和。

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

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 }


},

一切正常,直到我尝试编辑在sum列中计算的金额付费。我在使用 Math 函数进行编辑时似乎遇到了竞争条件。

异常(exception)情况是:

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)

是否有任何解决方法可以使总和仅在编辑后计算?或者避免在未定义的属性上计算此总和?

我尝试为这些列添加默认值,但根本没有帮助。

谢谢。

最佳答案

根据 @George 评论,由于 firebase 更改,$ 无法用作 firebase 键的前缀,因此 webix 数学运算失败。

解决方法是使用 Firebase 事务并自行计算。

关于firebase - 编辑列引发 `Cannot read property ' $sum' of undefined`、Webix DataTable 和 Firebase,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47246377/

相关文章:

android - LiveData 不会将类型推断为所需的返回值

java - 如何使用Java循环遍历Map中的数据

android - 具有客户端/应用身份验证而不是用户身份验证的 Firebase Android 应用

javascript - Ember.js - 在将一个组件添加到 Handlebars 模板之前,我可以将其嵌套到另一个组件中吗?

firebase - 如何将 Firebase 动态链接中的参数列入白名单

android - 如何检查 Firebase 云消息服务器中是否存在通知 key ?

javascript - 在图标上显示上下文菜单?

Javascript/Webix 将对象引用为数组

javascript - 如何设置字母组合过滤?

javascript - 数据表寻呼机宽度