Spreadsheet-like formulas on the DOM

前端 未结 6 1299
一个人的身影
一个人的身影 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:37

    You can use knockout.js to get the functionality you're looking for.

    Knockout.js implements an mvvm pattern in your javascript. Here is how they define MVVM:

    MVVM and View Models Model-View-View Model (MVVM) is a design pattern for building user interfaces. It describes how you can keep a potentially sophisticated UI simple by splitting it into three parts:

    A model: your application’s stored data. This data represents objects and operations in your business domain (e.g., bank accounts that can perform money transfers) and is independent of any UI. When using KO, you will usually make Ajax calls to some server-side code to read and write this stored model data.

    A view model: a pure-code representation of the data and operations on a UI. For example, if you’re implementing a list editor, your view model would be an object holding a list of items, and exposing methods to add and remove items.

    Note that this is not the UI itself: it doesn’t have any concept of buttons or display styles. It’s not the persisted data model either - it holds the unsaved data the user is working with. When using KO, your view models are pure JavaScript objects that hold no knowledge of HTML. Keeping the view model abstract in this way lets it stay simple, so you can manage more sophisticated behaviors without getting lost.

    A view: a visible, interactive UI representing the state of the view model. It displays information from the view model, sends commands to the view model (e.g., when the user clicks buttons), and updates whenever the state of the view model changes.

    When using KO, your view is simply your HTML document with declarative bindings to link it to the view model. Alternatively, you can use templates that generate HTML using data from your view model.

    So you'll create your "model" which includes the data in the spreadsheet, along with any functions you need to recalculate data. Then you'll have your view, which automatically updates (aka recalculates) the data as the user changes things on the page.

    http://knockoutjs.com

提交回复
热议问题