【问题标题】:Kendo UI: How to get the text input from the MultiselectKendo UI:如何从多选中获取文本输入
【发布时间】:2018-03-10 22:58:59
【问题描述】:

我正在尝试使用 Kendo UI MultiSelect 从 API 中选择一些内容。 API 不会返回所有项目,因为它们太多了。它只会返回包含searchTerm 的那些。

我试图弄清楚如何在 Kendo UI 多选中发送输入文本。当我说输入文本时,我的意思是用户在从列表中选择任何内容之前输入的内容。该文本必须传递给 DataSource transport.read 选项。

查看此 Codepen 以了解 https://codepen.io/emzero/pen/NYPQWx?editors=1011

注意:上面的例子不会做任何过滤。但是如果你输入“bre”,控制台应该会记录searching bre

【问题讨论】:

  • 如果提供的答案解决了您的问题,请告诉我?

标签: kendo-ui kendo-datasource kendo-multiselect


【解决方案1】:

在读取传输选项中使用 data 属性,这允许您通过返回一个稍后将在请求中序列化的对象来修改正在发送的查询。

默认读取的是 GET 请求,因此它将被添加到您指定的 url 的 queryString 中。

如果它是一个 POST,它将被添加到 POST 值中。

<div id="multiselect"></div>
  <script>
    $('#multiselect').kendoMultiSelect({
        dataTextField: 'first_name',
        dataValueField: 'id',
        filter: "startswith",
        dataSource: {
          serverFiltering: true, // <-- this is important to enable server filtering
          schema: {
                data: 'data'
          },
            transport: {
            read: {
                url: 'https://reqres.in/api/users',
              // this callback allows you to add to the request.
              data: function(e) {
                // get your widget.
                let widget = $('#multiselect').data('kendoMultiSelect');
                // get the text input
                let text = widget.input.val(); 
                // what you return here will be in the query string
                return {
                    text: text
                };
              }
           }
          }
        }
    });
  </script>

【讨论】:

  • 我不知道为什么这是通过“data”而不是“parameterMap”完成的,但这里有一个 read.data 上的链接 - docs.telerik.com/kendo-ui/api/javascript/data/datasource/…
  • @jaycer kendo 使用参数映射进行其他转换,我相信他们在参数映射期间调用数据处理程序。如果您查看 dataSourceTransport 类型属性,您会看到他们使用参数映射来更改发出传输的请求:{ odata: { parameterMap: function (options, type, useVersionFour) { var params, value, option, dataType;选项 = 选项 || {}; // 这里有更多代码。 } } }
猜你喜欢
  • 2020-01-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-01-10
  • 1970-01-01
  • 2014-03-03
相关资源
最近更新 更多