剑道UI - 指定数据源上读取的参数名称 [英] Kendo UI - Specify parameter name on dataSource read

查看:234
本文介绍了剑道UI - 指定数据源上读取的参数名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

剑道UI ,我使用的是自动完成框,试图从我的服务器检索数据。它撞上的 ASP.NET MVC 控制器具有以下签名。

With Kendo UI, I am using an autocomplete box to try and retrieve data from my server. It is hitting an ASP.NET MVC controller with the following signature.

public ActionResult aspect(string term){
   // ...
}

这意味着,请求需要在url中正确的参数。现在我遇到的问题是,我不能想出一个办法在数据源力学来指定。我已阅读文档的 parameterMap的几十次,这使得完全没有意义的我以任何方式。

This means that the request needs to have the correct parameter in the url. Now the issue I am running into is that I cannot discover a way to specify this in the dataSource mechanics. I have read the documentation on parameterMap dozens of times and it makes absolutely no sense to me in any way.

这是一个事实,即有问题的网页居然有10-15的自动完成的任一时刻的文本框,每个动态动态身份创建的。

This is complicated further by the fact that the page in question actually has 10-15 autocomplete text boxes at any one time, each dynamically created with dynamic identity.

在code,我使用至今如下:

The code I am using so far is as follows;

$(".autocomplete").kendoAutoComplete({
    dataTextField: "Name",
    dataSource: {
        type: "json",
        transport: {
            read: {
                url: "/search/aspect"
            }
        }
    }
});

那么,有什么我可以告诉它如何命名传递参数?

So is there anything I can do to tell it how to name the parameter it passes?

为了使它更清楚我想要做的,如果我是这样做的的jQuery 的,我会用...

To make it more clear what I am trying to do, if I were doing this in jQuery, I would use ...

$.ajax({ url: '/search/aspects', data: { term: (insert the data here) } });

但由于这一切的作品,没有设置选择,以获取自动完成输入,所以我不能检索输入表单元素它的价值的方式。

But because of the way all of this works, there is no set "selector" to get the autocomplete input, so I cannot retrieve its value from the input form element.

推荐答案

首先,通过设置该选项启用服务器端过滤:

First, enable server-side filtering by setting this option:

dataSource: {
    serverFiltering: true,

然后,值作为参数到 transport.parameterMap 函数的一个通过。

如果你登录传递给parameterMap的功能,这样的目标:

If you were to log the object passed in to the parameterMap function like this:

$(".autocomplete").kendoAutoComplete({
    dataTextField: "Name",
    dataSource: {
        serverFiltering: true,
        type: "json",
        transport: {
            read: {
                url: "/search/aspect"
            },
            parameterMap: function (data, action) {
                console.log(data);
            }
        }
    }
});

那么你将得到一个对象,它看起来像这样:

then you would get an object that looks like this:

{
    "filter":{
        "logic":"and",
        "filters":[
            {
                "value":"something",
                "operator":"contains",
                "field":"Name",
                "ignoreCase":true
            }
        ]
    }
}

所以,你可以用这个做来获得进入自动完成框中的值:

So you can use this to get the value entered into the AutoComplete box by doing:

$(".autocomplete").kendoAutoComplete({
    dataTextField: "Name",
    dataSource: {
        serverFiltering: true,
        type: "json",
        transport: {
            read: {
                url: "/search/aspect"
            },
            parameterMap: function (data, action) {
                if(action === "read") {
                    return {
                        term: data.filter.filters[0].value
                    };
                } else {
                    return data;
                }
            }
        }
    }
});

这篇关于剑道UI - 指定数据源上读取的参数名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆