jquery – DOM上的电子表格式公式

前端之家收集整理的这篇文章主要介绍了jquery – DOM上的电子表格式公式前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在寻找一种在我的DOM中动态绑定公式的方法.

我们有一个数据密集型应用程序,目前我写了很多处理程序来尝试重新计算和更新相应的单元格.但是,这是容易出错的.

我看到一些可能有能力的东西,hashigo.但是它还没有在一年半的时间里更新.

有没有人知道正在积极发展的类似的东西?我一直在寻找,但这是我设法找到的.

理想情况下,我只需要设置公式,它将处理监视,如果公式中的字段已更改,并相应地更新值.

编辑:我也是jQuerySheet,但它是比我可以使用的方式,我只需要公式解析它的方面.并且它的计算引擎似乎围绕具有列/行标识符的单元格旋转太多.

EDIT2:这个jQuery Calculation插件越来越接近我所需要的.

EDIT3:最终,我很想能够写出一些简单的东西

$('#output').formula(" ( SUM($('.x')) + $('#y') ) / ( funcThatReturnsValue() + 4 )");

每当*或#y中的值发生变化时,会导致重新计算#output的值.

但是,我可能会为此设定一些基本的东西

$('#output').formula({
    formula: "(SUM(x)+y)/(j+k)",variables: {
        x: $('.x'),y: $('#y'),j: function() {
            return 3;
        },k: 4
    }
    onblur: $('.x,#y')
});

解决方法

您可以使用knockout.js来获取您要查找的功能.

Knockout.js在你的javascript中实现一个mvvm模式.下面是他们如何定义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.

因此,您将创建包含电子表格中的数据的“模型”,以及重新计算数据所需的任何功能.然后,您将看到您的视图,当用户更改页面上的内容时,会自动更新数据(也就是重新计算)数据.

http://knockoutjs.com

猜你在找的jQuery相关文章