jQuery UI 自动完成 - 从 txt 文件中获取数据 [英] jQuery UI Autocomplete - get data from txt file

查看:22
本文介绍了jQuery UI 自动完成 - 从 txt 文件中获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 jQuery 初学者,试图让 jQuery UI 自动完成从 txt 文件中获取数据.txt格式很简单:

I'm jQuery beginner trying to make jQuery UI Autocomplete get data from txt file. Txt format is simple:

用户 1
用户 2
用户3

user1
user2
user3
etc.

代码是:

jQuery.get('users.txt', function(usersGet) {
    $( "#userLogin" ).autocomplete( {
        source: usersGet
    });
});

但不幸的是,这行不通.你能帮忙吗?谢谢!

But unfortunately that does not work. Can you please help? Thanks!

推荐答案

来自文档:

来源
字符串数组:
[ "选择 1", "选择 2" ]

Source
An Array of Strings:
[ "Choice1", "Choice2" ]

具有标签和值属性的对象数组:
[ { 标签:选择 1",值:值 1"},... ]

An Array of Objects with label and value properties:
[ { label: "Choice1", value: "value1" }, ... ]

您需要将文本文件修改为以下格式:

You need to amend your text file to be in this format:

["user1","user2","user3"]

然后将您的 jQuery 更改为:

Then change your jQuery to this:

$( "#userLogin" ).autocomplete({
    source: 'users.txt'
});

这篇关于jQuery UI 自动完成 - 从 txt 文件中获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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