无法显示带有typehead&amp ;;的bootstrap标签输入的建议。 ajax电话

时间:2016-10-13 15:46:47

标签: jquery twitter-bootstrap-3 bootstrap-typeahead bootstrap-tags-input

以下exp为我工作,

$('#casecustomtag').bstagsinput({
    typeahead: {
        displayText: function (text) {
            return text;
        },
        source: function (query, response) {
            return ['Business and industry', 'Economics and finance', 'Education and skills', 'Employment, jobs and careers', 'Environment', 'Government, politics and public administration', 'Health, well-being and care', 'Housing', 'Information and communication', 'International affairs and defence', 'Leisure and culture', 'Life inthe community', 'People and organisations', 'Public order, justice and rights', 'Science, technology and innovation', 'Transport and infrastructure']
        },
        minLength: 2
    },
    addOnBlur: true,
    freeInput: true,
    confirmKeys: [13],
    splitOn: null,
    writerWidth: 'auto'
});

但是当我尝试ajax通话时,我无法看到这个建议。不过,我的服务器得到了适当的响应

$('#casecustomtag').bstagsinput({
   typeahead: {
       displayText: function (text) {
           return text;
       },
       source: function (query, response) {
           return $.get('/ajax/customtags/gettags', {
               search: query,
               userId: 1
           }, function (data) {
               console.log(data);
               response =  $.map(data.data, function (item) {
                   console.log(item.text);
                   return item.text;                         
               });
               return response;
           }, 'json');
       },
       minLength: 2
   },
   addOnBlur: true,
   freeInput: true,
   confirmKeys: [13],
   splitOn: null,
   writerWidth: 'auto'
);

我正在使用Bootstrap 3作为参考我刚刚将tagsinput重命名为bstagsinput,因为它与其他jquery插件冲突。

拜托,有人帮我如何通过ajax动态显示建议吗? (我浪费了一整天的搜索解决方案但对我没用。

2 个答案:

答案 0 :(得分:1)

从内存中,响应参数是您需要使用返回的数据调用的函数,但是您要覆盖它。您应该在ajax调用的成功回调中调用响应函数。

src/config-comp/%.o

答案 1 :(得分:1)

浪费了一整天之后&代码调试我找到了解决方案。

    <field name="softId_suggest" type="int" indexed="true"  stored="true"  />
<copyField source="softId" dest="softId_suggest" /> 

我注意到需要完成,因为回调部分是由插件自己处理的。我在插件的下面现有代码中找到了。

 <lst name="suggester">
   <str name="name">MySuggest</str>
   <str name="lookupImpl">AnalyzingInfixLookupFactory</str>
   <str name="dictionaryImpl">DocumentExpressionDictionaryFactory</str>
   <str name="field">suggest_name</str>
   <str name="highlight">false</str>
   <str name="weightExpression">softId_suggest</str>       
   <str name="indexPath">analyzingInfixSuggesterIndexDir</str>
   <str name="suggestAnalyzerFieldType">text_suggest</str>
 </lst>