【问题标题】:autocomplete with freebase and jsonp使用 freebase 和 jsonp 自动完成
【发布时间】:2012-02-27 11:04:25
【问题描述】:

我正在尝试使用 Jquery-ui 自动完成的示例来与 Freebase 一起使用。此外,我正在使用 tag-it 插件...

这是我正在尝试但不起作用的方法:

$(function() {
    $("#tags").tagit({
        tagSource: function( request, response ) {
                        $.ajax({
                            url: "https://www.googleapis.com/freebase/v1/search",
                            dataType: "jsonp",
                            data: {
                                limit: 12,
                                name: request.term
                            },
                            success: function( data ) {
                                response( $.map( data.result, function( item ) {
                                    return {
                                        label: item.name,
                                        value: item.name
                                    }
                                }));
                            }
                        });
        }
    });
});

使用类似:https://www.googleapis.com/freebase/v1/search?query=ambrose%20b&indent=true

示例 JSON

{
  "status": "200 OK",
  "result": [
    {
      "mid": "/m/0dkdnj6",
      "name": "Ambrose B. Rathborne",
      "notable": {
        "name": "Author",
        "id": "/book/author"
      },
      "lang": "en",
      "score": 71.059212
    },
    {
      "mid": "/m/0m17",
      "name": "Ambrose Bierce",
      "notable": {
        "name": "Journalist",
        "id": "/m/0d8qb"
      },
      "lang": "en",
      "score": 34.444187
    }.....

从确实有效的示例中:

$(function() {
    $("#tags").tagit({
        tagSource: function( request, response ) {
                        $.ajax({
                            url: "http://ws.geonames.org/searchJSON",
                            dataType: "jsonp",
                            data: {
                                featureClass: "P",
                                style: "full",
                                maxRows: 12,
                                name_startsWith: request.term
                            },
                            success: function( data ) {
                                response( $.map( data.geonames, function( item ) {
                                    return {
                                        label: item.name + (item.adminName1 ? ", " + item.adminName1 : "") + ", " + item.countryName,
                                        value: item.name
                                    }
                                }));
                            }
                        });
        }
    });
});

【问题讨论】:

    标签: jquery-ui jquery jquery-ui-autocomplete freebase


    【解决方案1】:

    你几乎是对的。你的输入有误,试试:

    $(function() {
        $("#tags").tagit({
            tagSource: function( request, response ) {
                            $.ajax({
                                url: "https://www.googleapis.com/freebase/v1/search",
                                dataType: "jsonp",
                                data: {
                                    limit: 12,
                                    query: request.term
                                },
                                success: function( data ) {
                                    response( $.map( data.result, function( item ) {
                                        return {
                                            label: item.name,
                                            value: item.name
                                        }
                                    }));
                                }
                            });
            }
        });
    });
    

    【讨论】:

      猜你喜欢
      • 2011-09-15
      • 2012-04-26
      • 2015-12-13
      • 2012-11-06
      • 2014-05-31
      • 2012-11-15
      • 1970-01-01
      • 2012-06-12
      • 1970-01-01
      相关资源
      最近更新 更多