0

我正在尝试从用作我的网格的自定义过滤器编辑器的 KendoDropDownList 中获取所选项目的数据参数。

我有:

function gradeSelector(element)
{
  element.kendoDropDownList({
    dataSource: {
      transport: {
        read: {
          type: "POST",
          url: ROOT+'record/fetchGrade',
          dataType: 'json',
          data: {
            mode: 'obj'
          }
        }
      }
    },
    optionLabel: "Select grade",
    dataTextField: "text",
    dataValueField: "id",
    template: '#="<span class=\'filterTrigger\' data-value=\'"+id+"\'>"+text+"</span>" #',
    select: function(e) 
    {// Dirty, is there a better way?
      html = e.item[0].outerHTML;
      html = html.substring(html.indexOf('data-value="')+12);      
      gradeId = html.substring(0, html.indexOf('"'));

      clearSingleFilter('grade');
      activeFilter.push({
        field: 'grade',
        operator: 'eq',
        value: gradeId
      })
      $('.k-animation-container').hide();
      filtersState = 1 ;
      $('#customerGrid').data('kendoGrid').dataSource.filter(activeFilter);
    }
  });
}

我得到gradeId的方式看起来很乱。检索此值的正确方法是什么?

4

1 回答 1

0

考虑使用closeevent 而不是,select然后您可以简单地执行以下操作:

close         : function (e) {
    // Easily get gradeId
    var gradeId = this.select();

    clearSingleFilter('grade');
    activeFilter.push({
        field   : 'grade',
        operator: 'eq',
        value   : gradeId
    })
    $('.k-animation-container').hide();
    filtersState = 1;
    $('#customerGrid').data('kendoGrid').dataSource.filter(activeFilter);
}

“问题”select在于它在元素被触发之前触发,因此您无法(轻松)获取值,而是close在实际选择值之后触发。

编辑:如果列表id未排序且连续,则先前的实现将失败。作为一般解决方案,您应该使用:

close         : function (e) {
    // Get index in the list
    var idx = this.select();
    // Get the item corresponding to that index
    var item = this.dataItem(idx);
    // Now, we can get the id from the item
    var gradeId = item.id;
    console.log("gradeId", gradeId);

    clearSingleFilter('grade');
    activeFilter.push({
        field   : 'grade',
        operator: 'eq',
        value   : gradeId
    })
    $('.k-animation-container').hide();
    filtersState = 1;
    $('#customerGrid').data('kendoGrid').dataSource.filter(activeFilter);
}
于 2013-05-09T12:11:06.980 回答