[asp.net] easyui onBeginEdit事件和onBeforeEdit事件的区别

今天在使用easyui的过程中,需要获取combobox对象,并设置其不可用。起初在onBeforeEdit事件获取combobox对象,结果总是null,最后看到easyui的api后恍然大悟。


由于我们只有在进入编辑模式后采用获取combobox的editor对象,所以我们必须在onBeginEdit写获取combobox对象的业务逻辑。笔者使用onBeforeEdit来获取将要编辑的行数据,用于进行数据的回显;使用onBeginEdit获取datagrid对象的各个对象,如combobox的editor对象等,进而对其属性进行设置。详细的过程如下所示:

onBeforeEdit: function (index, row) {
    tmpRowData = row;//tmpRowData为全局变量,负责存放待修改行的数据(json格式)
}
onBeginEdit: function (index, row) {
    var target = datagrid.datagrid('getEditor', { index: index, field: 'JZId' }).target;
    //target.combobox({ editable: false });  //不可以输入,只可以选择
    if (row.Id != undefined) {
        target.combobox({ disabled: true });
    } else {
        target.combobox({ disabled: false });
    }
}

这里需要注意的是,设置下拉列表只能通过选择设置值的方式是设置editable为false;

设置下拉列表不可用的方式是设置disabled属性值为true。

猜你喜欢

转载自blog.csdn.net/zyxhangiian123456789/article/details/80987735