我在页面中有一个网格想要添加onCellchange功能,但是添加网格时却出现了一个JS错误:

oppLineGrid.onCellchange.subscribe(function (e, args) {
       Uncaught TypeError: Cannot call method 'subscribe' of undefined
            alert('changed');
        });


这是我的代码,排序功能正常工作,我认为onCellchange的添加顺序不正确。非常感谢。

function loadOppLineGrid(data) {
    oppLineGrid = new Slick.Grid("#oppLineGrid", data, oppLineColumns, oppLineOptions);

    oppLineGrid.onCellchange.subscribe(function (e, args) {
        alert('changed');
    });

    oppLineGrid.onSort.subscribe(function (e, args) {
        var cols = args.sortCols;

        oppLineGridData.sort(function (dataRow1, dataRow2) {
            for (var i = 0, l = cols.length; i < l; i++) {
                var field = cols[i].sortCol.field;
                var sign = cols[i].sortAsc ? 1 : -1;
                var value1 = dataRow1[field], value2 = dataRow2[field];
                var result = (value1 == value2 ? 0 : (value1 > value2 ? 1 : -1)) * sign;
                if (result != 0) {
                    return result;
                }
            }
            return 0;
        });
        oppLineGrid.invalidate();
        oppLineGrid.render();
    });
    oppLineGrid.init();

}

最佳答案

Javascript是区分大小写的语言。事件名称为onCellChange(大写C):

oppLineGrid.onCellChange.subscribe(function(e, args) {
    alert('changed');
});

08-19 03:00