2017-11-12 14 views
4

Firebase에서 레코드를 편집하고 Math 연산으로 두 레코드 합계를 계산하기 위해 Webix DataTable을 사용하려고합니다.

내 데이터 테이블의 일부입니다 : 내가 편집하려고 할 때까지

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 또는 sum 열에서 계산 paid. 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) 

는 합계는 편집 후 계산하게 주변에 어떤 일이 있습니까? 또는이 합계가 정의되지 않은 속성에서 계산되지 않도록 하시겠습니까?

해당 열에 기본값을 배치하려했지만 전혀 도움이되지 않습니다.

감사합니다.

+0

'$'는 최신 firebase 업데이트 – George

+0

+에서 제거했습니다. 무엇을 시도하고 있는지 이해하기 위해 더 많은 코드를 추가해야합니다. – George

+0

'$'는 webix 수학 함수의 일부입니다. 나는 그것을 피할 수 없다. –

답변

0

@George 주석에 따라 firebase 변경으로 인해 $은 firebase 키의 접두사로 사용할 수 없으므로 webix 수학이 실패합니다.

해결 방법은 firebase 트랜잭션을 사용하고 직접 계산하는 것입니다.