我有这个脚本:逗号脚本数据库
$.get('file.txt', function(x) {
var i;
var pos = 0;
var availableTags = [];
x = x.split(/[\;,\n]+/);
for (i = 0; i < x.length; i = i + 2)
availableTags[pos++] = x[i];
console.log(availableTags);
$(function() {
$("#search").autocomplete({
source: availableTags
});
});
}, 'text');
我想它来阅读这个file.txt的
Supermarket;big shop where a wide range of products is sold
Station;a place where you can take a train, a bus, etc.
School;place where students learn
虽然逗号并不是spliters,剧本理解的第一列他们是,并且在第二行的逗号之后,阅读错误,因为它理解公共汽车等项目。任何建议?
你为什么不从REG-EXP,除去逗号'X = x.split(/ [\; \ n] + /);' – dreamweiver
是给出的file.txt,并且不会改变?服务器端响应应该尝试产生一些对象格式,如:{tag:“supermarket”,desc:“大商店...”},{tag:“station”,desc:“一个地方...”}等等上。这会让客户端的处理更轻松 – errand
嗯,我很抱歉,但它就像dreamweiver的答案一样简单。以为我曾尝试......这是工作到很晚的问题。我应该删除这个问题吗? – Kathlyn