简体   繁体   English

YUI自动完成URL本地数据源

[英]YUI autocomplete url local datasource

I have an array that resides on the same domain as my html and I want to use the array as the source for an autocomplete textbox. 我有一个数组,该数组与html驻留在同一域中,我想将该数组用作自动完成文本框的源。 Contents of myarr.json (1 MB): myarr.json内容(1 MB):

["Aaronsburg, PA", "Abanda, AL", "Abbeville, AL", "Abbeville, GA" ... ]

I am using YUI2: AutoComplete and it works if I embed (a portion of) the array like this: 我正在使用YUI2: 自动完成 ,如果我像这样嵌入 (部分)数组,则可以使用:

var myDataSource = 
    new YAHOO.util.LocalDataSource(["Aaronsburg, PA", "Abanda, AL"]);

but my array is huge so I must link to it. 但是我的数组很大,所以我必须链接到它。 When I do that: 当我这样做时:

var myDataSource = 
    new YAHOO.util.LocalDataSource("http://mydomain.com/myarr.json");

the console responds: GET http://mydomain.com/myarr.json/search/aarons/other/data 404 (Not Found) 控制台会回应: GET http://mydomain.com/myarr.json/search/aarons/other/data 404 (Not Found)

How do I turn my array into json that can respond to the /search component of that GET statement? 如何将数组转换为可以响应该GET语句的/search组件的json?

If you want to "link" to it, you should just use the Remote Datasource . 如果要“链接”到它,则应仅使用Remote Datasource

The Examples go through how to Customize your datasource parsing. 这些示例介绍了如何自定义数据源解析。

YUI has very extensive documentation on all of this. YUI在所有这些方面都有非常详尽的文档。

[Edit] [编辑]

In response to your comment, see the Datasource Docs 针对您的评论,请参阅数据源文档

Mainly under "Simple JavaScript Array", 主要在“简单JavaScript数组”下,

myDataSource.responseSchema = {
    fields: ["name"]
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM