【问题标题】:PUT method and payload with devbridge Jquery Autocomplete Plugin使用 devbridge Jquery Autocomplete Plugin 的 PUT 方法和有效负载
【发布时间】:2015-06-09 23:53:14
【问题描述】:

我正在为 JQuery 使用 devbridge 自动完成插件。

到目前为止,我可以调用我的 Rest API 并获得一些结果。 My Rest Api 接受使用 PUT 方法的查询。但基本上我需要在查询中传递我的文本字段(客户)的值。

基本上,每次值更改时,我都需要更新数据有效负载的值。但是 $( "#customer" ).val() 在我跟踪开发者控制台时是空的。

我认为我没有以正确的方式使用它。服务应该返回所有结果,然后在搜索框中过滤。但是由于某些原因,当我在搜索框中输入内容时,它没有被过滤。我在列表框中有所有结果。

我尝试了以下代码,但它不起作用。

<script>
$(document).ready(function() {
    $( "#customer" ).devbridgeAutocomplete({
            serviceUrl: 'http://localhost:8080/services/rest/data/Customer/query',
            type: 'PUT',
            dataType: 'text',
            ajaxSettings: {
                'data': '{"select": {"from": ["Customer"],"where": {"full_text": [{"value": "'+$( "#customer" ).val()+'"}]}}}',
                'contentType': 'application/json',
                headers: {
                    'Authorization': 'Basic YXXtXX5pcXXyYXRvXXphZG1pbmlzdHJhdG9y'
                },
            },
            transformResult: function(response) {
                var responseObj = jQuery.parseJSON( response );

                return { suggestions: $.map(responseObj, function(data) {
                    return { value: data.customer.fullname, data: data.customer.mdmcustid };
                })};
            },
            onSelect: function (suggestion) {
                console.log('You selected: ' + suggestion.value + ', ' + suggestion.data);
            },
            onSearchStart: function (query) {
                console.log('Search terms: ' + $( "#customer" ).val());
            }
    });
});
</script>

你能告诉我如何解决这个问题吗?

非常感谢

【问题讨论】:

    标签: javascript jquery autocomplete jquery-autocomplete


    【解决方案1】:

    它正在使用自定义查找,但我不知道这是否是最好的方法。

    lookup: function (query, done) {
                $.ajax({
                    type: "PUT",
                    url: "http://localhost:8080/talendmdm/services/rest/data/Customer/query",
                    contentType: "application/json",
                    data: '{"select": {"from": ["Customer"],"where": {"full_text": [{"value": "'+$( "#customer" ).val()+'"}]}}}',
                    dataType: "text",
                    headers: {
                        'Authorization': 'Basic YWRtaW5pc3RyYXRvcjphZG1pbmlzdHJhdG9y'
                    },
                    success: function (res) {
                        var suggestionObj = { suggestions: $.map(jQuery.parseJSON( res ), function(data) {
                            return { value: data.customer.fullname, data: data.customer.mdmcustid };
                        })};
    
                        done(suggestionObj);
                    },
                    error: function (xhr, status, error) {
                        console.log( 'Query KO' );
                    }
                });
            },
            onSelect: function (suggestion) {
                console.log('You selected: ' + suggestion.value + ', ' + suggestion.data);
            }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-02-23
      • 1970-01-01
      • 1970-01-01
      • 2015-08-26
      • 2018-09-17
      • 2015-04-09
      • 2021-02-28
      相关资源
      最近更新 更多