2016-08-10 2 views
1

동거하지 않는 이유는 무엇입니까?부트 스트랩 선행 입력 및 Tagsinput 내가이 스크립트를 만들어 완벽하게 작동

은 이걸로 시도했지만 성공하지 :

Uncaught TypeError: process is not a function 

내가 무엇을 할 수

$('.js_tags').tagsinput({ 
     typeahead:{ 
      minLength: 3, 
      source: function (query, process) { 
      return $.ajax ({ 
       url: '/app/route', 
       type: 'POST', 
       data: 'query='+query, 
       dataType: "json", 
       async: true, 
       success: function (data){ 
        process(data); 
       }, 
       error: function (request, status, error) { 
        console.log(request.responseText); 
       } 
      }) 
     }, 
}); 

내가 얻을?

:

이 같은 JSON 데이터를 소비하는 당신에게

+0

process() 란 무엇입니까? –

+0

은 스크롤에서 항목을 밀어 넣을 수있는 대표적인 fn입니다. 어떻게 선행 및 태그 입력을 함께 구현할 수 있습니까? 아약스 포스트 콜을 사용하여 .. –

답변

0
$('.typeahead').typeahead({ 
    source: function (query, process) { 
     return $.get('/typeahead', { query: query }, function (data) { 
      return process(data.options); 
     }); 
    } 
}); 

감사 ..

나는 몇 가지 물건을 시도했지만 그들 중 누구도 내가 다른 구성 요소를 사용하지 않으 ... 작동하지 않습니다 Tagsinputs를 들어
{ 
    "options": [ 
     "Option 1", 
     "Option 2", 
     "Option 3", 
     "Option 4", 
     "Option 5" 
    ] 
} 

$('.tagsInput').tagsinput({ 
     minLength: 3, 
     typeahead: {     
      source: function(query) { 
      return $.get('/app/route').done(function(data){ 
       /*if you have add `content-type: application/json` in 
       server response then no need to parse JSON otherwise, 
       you will need to parse response into JSON.*/ 
       return $.parseJSON(data); 
      }) 
      } 
     } 
}); 

참고 : 데이터는 JSON으로 반환됩니다.