typeahead.js 中的音译 [英] Transliteration in typeahead.js

查看:26
本文介绍了typeahead.js 中的音译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,请检查:http://ws.luyencong.net/data/search/query.php?do=advanced

您可以将该 JSON 的所有内容粘贴到此处:http://pro.jsonlint.com/

You can paste all the content of that JSON to here : http://pro.jsonlint.com/

现在您可以看到该 JSON 的内容是越南语.好吧,我希望用户搜索时他们可以使用 UTF-8 字符进行搜索.

Now you can see the content of that JSON is in Vietnamese. And well, I want when user search they can search with UTF-8 character.

例如:您在搜索框中键入字符ô",建议应显示.(Typeahead.js 现在不能这样做).

For example: You type in the search box character 'ô', the suggestion should displays. (Typeahead.js now can't do that).

有什么办法可以满足我的要求吗?

Is there any way can do my requirements ?

您可以在 http://www.luyencong.net 看到现场演示(在搜索中输入一个字符框)

You can see a live demo at http://www.luyencong.net (type a character in search box)

推荐答案

这不是一个优雅的解决方案,但您可以利用自定义标记来获得音译支持.例如,如果您有以下数据:

It's not an elegant solution, but you could take advantage of custom tokens to get transliteration support. For example, if you had the following datum:

{
  "value": "limón fútbol"
} 

默认情况下,它会被标记为 ['limón', 'fútbol'].但是,如果您自己明确设置令牌,则可以执行以下操作:

By default, it would get tokenized into ['limón', 'fútbol']. If you explicitly set the tokens yourself however, you could do something like this:

{
  "value": "limón fútbol",
  "tokens": ["limon", "limón", "futbol", "fútbol"]
}

现在,如果您搜索 limonfutbol,此数据将作为建议显示.

Now if you searched for limon or futbol, this datum would be show as a suggestion.

这篇关于typeahead.js 中的音译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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