具有最小化数据集的twitter typeahead

时间:2015-08-02 21:58:16

标签: javascript typeahead bloodhound

我的最终目标是创建一个提前输入(TA),可以在键值设置中用于后续操作。我在初始化基本问题时遇到了问题。

我有一张超过50M地址的表格。我意识到这对TA来说太过分了,所以我最初的想法是通过zipcode分割数据集,这可以减少大约6K-10K的可能性。为此,我有以下代码:

var addresses = new Bloodhound({
    datumTokenizer: function (datum) {
        return Bloodhound.tokenizers.whitespace(datum.value);
    },
    queryTokenizer: Bloodhound.tokenizers.whitespace,
    prefetch: {
        url: "http://live2.offrs.com/buyerherodev/data/addressTA.cfm?zip="+zip,
        cacheKey: "change here!"
    }
});

$('.typeahead').typeahead(null, {
  name: 'addresses',
  source: addresses,
  display: 'Address',
});

值得注意的是,zip由URL GET Variable传递。在我的例子中,我使用的是20001

JSON返回格式为:[{" ParcelID":"","地址":""},{& #34; ParcelID":"","地址":""}]

我需要可以搜索地址,并且选择ParcelID存储在值中以进行进一步操作。

HTML:

<div id="menu">
        <input tabindex="-1" spellcheck="false" autocomplete="off" readonly="" style="position: absolute; top: 20px; left: 0px; border-color: transparent; box-shadow: none; opacity: 1; background: rgb(255, 255, 255) none repeat scroll 0% 0%;" class="form-control typeahead tt-hint" type="text">
        <input dir="auto" style="position: relative; vertical-align: top; background-color: transparent;" spellcheck="false" autocomplete="off" id="address" class="form-control typeahead tt-input" placeholder="Locate by Address..." type="text">
        <pre style="position: absolute; visibility: hidden; white-space: pre; font-family: &quot;Helvetica Neue&quot;,Helvetica,Arial,sans-serif; font-size: 16px; font-style: normal; font-variant: normal; font-weight: 400; word-spacing: 0px; letter-spacing: 0px; text-indent: 0px; text-rendering: optimizelegibility; text-transform: none;" aria-hidden="true"></pre>
        <span style="position: absolute; top: 100%; left: 0px; z-index: 100; display: none; right: auto;" class="tt-dropdown-menu">
            <div class="tt-dataset-states"></div>
        </span>
    <div id= "fulldata"></div>
</div>

非常感谢任何帮助。 非常感谢

0 个答案:

没有答案
相关问题