简体   繁体   English

输入元素未触发更改事件

[英]change event not triggered on input element

The following marionette view contains a table that is editable by double clicking a cell. 下面的木偶视图包含一个可通过双击单元格进行编辑的表。 To accomplish that I used slickgrid. 为此,我使用了slickgrid。 It works fine in chrome, but in IE9 this view never notices the change event("change .slick-cell.l1 input"). 它在chrome中工作正常,但是在IE9中,此视图从不注意到更改事件(“ change .slick-cell.l1 input”)。 This is unless you double click the cell to edit make the change then click the save button. 除非您双击要编辑的单元格进行更改,然后单击“保存”按钮。 In chrome I can double click the cell make the change and hit enter or click anywhere outside the cell and the change occurs. 在chrome中,我可以双击该单元格进行更改,然后按Enter键或单击该单元格外部的任意位置即可进行更改。

DataContentView = Marionette.ItemView.extend({
    className: "ui-widget-content grid-container",

    events: {
        "change .slick-cell.l0 input": "changeDataKey",
        "change .slick-cell.l1 input": "changeDataValue",
        "click .ui-icon-trash": "removeData"
    },

    changeDataValue: function(event){                
        var target = $(event.target),
            key = target.closest(".slick-row").find(".l0").text(),
            value = target.val();

        this.model.set(key, value, {silent:true});
    }
}
"input .slick-cell.l0 input": "changeDataKey",
// and similar to others

try bind 'input' event if your IE version is >=9 or 'propertychange' event. 如果您的IE版本> = 9或“ propertychange”事件,请尝试绑定“ input”事件。 It can help. 它可以提供帮助。

Using different events did seem to work for IE9. 使用不同的事件似乎确实适用于IE9。 I found what I think maybe a better solution. 我发现我认为可能是更好的解决方案。 Intially I used the keyup event to call changeDataValue function. 最初,我使用keyup事件来调用changeDataValue函数。 This worked well except in cases where the enter key or the escape key was pressed. 除按下回车键或退出键的情况外,此方法效果很好。 Slickgrid seems to stop propagation of those key events. Slickgrid似乎阻止了这些关键事件的传播。 To get around this slick grid has its own set of events. 为了避开这个光滑的网格,它有自己的事件集。 So I found the right event onCellChange , here is the code I used: 所以我找到了正确的事件onCellChange ,这是我使用的代码:

this.grid = new Slick.Grid();       

this.grid.onCellChange.subscribe(function(e,args){
    if(args.cell === 0){//cell in first column changed
        this.changeDataKey(args.item.key, args.item.val);
    }
    else if(args.cell === 1){
        this.changeDataValue(args.item.key, args.item.val);
    }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM