jQuery用户界面自动完成 - 获得txt文件数据 [英] jQuery UI Autocomplete - get data from txt file

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

问题描述

我jQuery的初学者试图让jQuery用户界面自动完成获得txt文件的数据。 TXT格式很简单:

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

user1的结果
  user2的结果
  用户3结果
  等等。

user1
user2
user3
etc.

code是:

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

但不幸的是,这并不工作。可以请你帮忙吗?谢谢!

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

推荐答案

从文档:

源代码结果
  字符串数组:结果
  [Choice1,选择2]

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

与标签和值属性的对象的数组:结果
  [{标号:Choice1值:值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用户界面自动完成 - 获得txt文件数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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