Twitter Typeahead和Handlebars

时间:2015-09-22 00:52:07

标签: handlebars.js typeahead.js bootstrap-typeahead

我在实施一个想法时遇到了一些麻烦,我不得不将twitter的预先建议属性变得有点动态。

我有以下代码:

$(inputElement).typeahead({
        highlight: true,
        hint: false
    }, {
        name: 'engine',
        limit: 15,
        displayKey: config.displayKey,
        source: config.engine.ttAdapter(),
        templates: {
            empty: [
                '<div class="empty-suggestion-message">',
                    'No results matched your query.',
                '</div>'
            ].join('\n'),
            suggestion: Handlebars.compile('<p> <span>{{name}}</span> - <span>{{email}}</span> - <span>{{phone}}</span> </p>'),
        }
    });

在Handlebars.compile部分,我打印了源的响应键,姓名,电子邮件和电话。我想要做的是,设置一个对象来保存一些配置:

var _setConfig = function (url, query, displaykey, suggestion) {
    config.url = url;
    config.query = query;
    config.displayKey = displaykey;
    config.suggestion = suggestion;
    console.log(config.suggestion);
};

我想将建议部分更改为:

suggestion: Handlebars.compile('<p> <span>{{config.suggestion[0]}}</span> - <span>{{config.suggestion[1]}}</span> - <span>{{config.suggestion[2]}}</span> </p>')

假设我将一个数组(e,g [&#39; name&#39;,&#39; email&#39;,&#39; phone&#39;])作为_setConfig的建议参数传入( )功能。

任何想法??

谢谢:D

0 个答案:

没有答案