Spreadsheet-like formulas on the DOM

前端 未结 6 1293
一个人的身影
一个人的身影 2021-02-13 20:46

I am looking for a way to dynamically bind formulas throughout my DOM.

We have a data intensive app, and currently I write many handlers to try and recalculate and updat

6条回答
  •  无人共我
    2021-02-13 21:43

    You can approach the problem like this:

    • by storing the vars on the DOM node you want to keep update via $('myDomElement').data('varX',data);
    • by overloading the setData-method for that DOM node via $("myDomElement").bind("setData", function(key,value){ setTimeout(function() { $("myDomElement").trigger("formula"); },10); return value; });
    • and by finally creating your update formula like $('myDomElement').bind("formula",function() { this.html(foo()); });

    Woehoe, I reread your post and found you don't really specify you have vars in which you store the data ... instead you got cells ...

    • in this case you could just add a changeHandler to the cells that update the formula ..

    hmmm, actually, I think I forgot what the problem was, it seems a bit too obvious what I'm supposing here ... sorry if of no help

    anyway ... I did a quick google on data binding jquery, that's where I found you can bind the setData/getData-events on $.data: What you might not know about jquery

    I also found this, which might or not be of interest to your spreadsheety-approach: using jquery.data to detect form changes

    What's more, I agree with previous answers, you could always use a framework -- personally I prefer jsmvc

提交回复
热议问题