【问题标题】:Kendo - insert event attribute剑道 - 插入事件属性
【发布时间】:2015-11-13 05:05:23
【问题描述】:

我创建了一个通用的 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});

【问题讨论】:

    标签: javascript html asp.net-mvc-4 kendo-ui


    【解决方案1】:

    您的建议应该可以正常工作。在您的函数中,只需在设置网格属性时检查对象属性:

    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,
       });
    

    }

    工作DEMO

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-24
      • 2020-01-26
      • 1970-01-01
      相关资源
      最近更新 更多