0

我正在使用 Wijmo SpreadJS。当单元格数据(或电子表格中的任何内容)发生更改时,我需要触发事件。从文档中我发现了这两个:

  • CellChanged - 当任何单元格中的数据发生变化时触发
  • RangeChanged - 删除单元格数据时触发

因此,我需要为这两个事件触发相同的功能,但它不起作用:

function (){
    var spread = $("#ss").wijspread("spread");

    spread.bind($.wijmo.wijspread.Events.RangeChanged $.wijmo.wijspread.Events.CellChanged, function (sender, args) {
        setTimeout(function(){
            $.ajax({
                    /// code here
                   });  
        },0);
    });
};

我没有收到任何错误,但这两个事件都没有被触发。

4

2 回答 2

0

$.bind需要一串事件。您尝试传递的参数值:

$.wijmo.wijspread.Events.RangeChanged $.wijmo.wijspread.Events.CellChanged

不是有效的 JS 语法。

尝试

function (){
    var spread = $("#ss").wijspread("spread");
    var myEventHandler = function (sender, args) {
        // code to handle events
    }

    spread.bind($.wijmo.wijspread.Events.RangeChanged, myEventHandler);
    spread.bind($.wijmo.wijspread.Events.CellChanged, myEventHandler);
};

或者

function (){
    var spread = $("#ss").wijspread("spread");
    var myEventHandler = function (sender, args) {
        // code to handle events
    }

    var eventsToBind = $.wijmo.wijspread.Events.CellChanged + " " + $.wijmo.wijspread.Events.RangeChanged;
    spread.bind(eventsToBind, myEventHandler);
};
于 2013-10-15T21:07:28.753 回答
0

如果这些事件的类型是字符串,您可以这样做:

spread.bind($.wijmo.wijspread.Events.RangeChanged + ' ' + $.wijmo.wijspread.Events.CellChanged, function (sender, args) {

如果它们不是字符串,并且您无法获得表示事件的字符串,您可能需要这样做:

function changeHandler(sender, args) {
    setTimeout(function(){
        $.ajax({
            /// code here
        });  
    },0);
}

spread
    .bind($.wijmo.wijspread.Events.RangeChanged, changeHandler)
    .bind($.wijmo.wijspread.Events.CellChanged, changeHandler);
于 2013-10-15T20:53:56.977 回答