开发者

json with Autocomplete?

开发者 https://www.devze.com 2022-12-24 07:13 出处:网络
I am using Jquery Autocomplete I am also using the formatItem. I would like the output to be <json.key: json.value

I am using Jquery Autocomplete

I am also using the formatItem. I would like the output to be

<json.key: json.value

ex

Name: Adam

However i cant get the json data using the 4th param and i am getting the full json string as the 4th param and one resul开发者_JAVA百科t. How do i use json with this? is another autocomplete recommended? (this one looks pretty good...)


Check out the jQuery UI Autocomplete plugin


i'm using the jQuery UI with this code:

function initAutocomplete() {
        $("#tbDevices").autocomplete("Static/ui.autocomplete/GetDevices.ashx", {
            width: 160,
            selectFirst: false,
            max: 100,
            autoFill: true,
            matchContains: true,
            highlightItem: true,
            parse: function(data) {
                return $.map(eval(data), function(row) {
                    return {
                        data: row,
                        lable: row.lable, //value being searched for
                        value: row.value //value in text input
                    }
                });
            },
            formatItem: function(row, i, max, term) {
                return "<span style='font-size: 110%;'>" + row.lable + "</span><br/>" + "ID: " + row.value;
            },
            formatResult: function(row, i, max) {
                return row;
            }
        }).result(function(event, item) {
            document.getElementById('#hdnChosenDevice').value = item.value;
            $('#tbDevices').val(item.lable);
        });
    }   

the ashx file is returning a string with json :

[{"lable":"device1","value":"01"},{"lable":"device2","value":"02"}]


I doubt this is still relevant for this question, but for completeness' sake I'll include the standalone jQuery autocompleter plugin that is still around (and actively developed):

http://code.google.com/p/jquery-autocomplete/



You cannot change the json format because its a standard. Since its hard to construct it at server side , my suggestion is to go for a JSON api .
You need not worry about the formatting
Also make sure to set the response as "application/json"

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号