剑道-插入事件属性

Kendo - insert event attribute

本文关键字:属性 入事件 插入 剑道      更新时间:2023-09-26

我创建了一个通用的js DataGrid创建者,代码如下:

function createGrid(targetDiv, mycolums, source, fnChange) {
  return $(targetDiv).kendoGrid({
      dataSource: {
          data: source,
          pageSize: 20
       },
      scrollable: true,
      sortable: true,
      pageable: {
        input: true,
        numeric: false
       },
    columns: mycolums, 
    change: fnChange
});
}

称之为

createGrid("#grid1", columns, dataSource, onChange);

它工作得很好,但我想以某种方式修改我的创建网格函数,因为有时一些网格需要绑定到其他事件,如edit : fnEdit等。

我的问题是,如何修改createGrid以接受对象而不是特定参数。比方说,我想把它做成这样的东西:

function createGrid(targetDiv, mycolums, source, OtherAttributes) {
  return $(targetDiv).kendoGrid({
      dataSource: {
          data: source,
          pageSize: 20
       },
      scrollable: true,
      columns: mycolums, 
      OtherAttributes
   });

这样我就可以称之为:

createGrid("#grid1", columns, dataSource, {change: OnChange, edit: OnEdit});

您的建议应该很有效。在您的函数中,只需在设置网格属性时检查对象属性:

var otherAttrs = {
  change: onChange,
  dataBound: onDatabound                  
};
createGrid(div, cols, datas, otherAttrs);
function createGrid(targetDiv, mycolums, source, opts) {
    return $(targetDiv).kendoGrid({
        dataSource: {
            data: source,
            pageSize: 20
         },
        scrollable: true,
        sortable: true,
        selectable: "multiple, row",
        pageable: {
          input: true,
          numeric: false
        },
        columns: mycolums, 
        change: opts.change ? opts.change : null,
        dataBound: opts.dataBound ? opts.dataBound : null,
   });

}

工作演示