2017-10-16 1 views
1

나는이 테이블는 선행 입력하고 첫 번째 셀을 선택

<table id="vehicleParamTable" class="table table-striped"> 
    <thead> 
     <tr> 
      <th>Name</th> 
      <th>Description</th> 
     </tr> 
    </thead> 
    <tbody> 
    </tbody>  
</table> 

있습니다. 잘 됐네. 행의 첫 번째 열에서

, 나는

선택기가 작동하지 않는 JQuery와 - typehead를 추가, 또한 첫 번째 행 (일 헤더)

$('#vehicleParamTable tr td:first-child').typeahead({ 
    minLength: 2, 
    display: "name", 
    mustSelectItem: true, 
    emptyTemplate: function(query) { 
    //must reset current element here 
    return 'No result for "' + query + '"'; 
    }, 
    source: { 
    vehicleParam: { 
     ajax: { 
     url: "/rest/vehicleparam", 
     path: "content" 
     } 
    } 
    }, 
    callback: { 
    onEnter: function(node, a, item, event) { 
     //must assign item.id to current current element id 
    }, 
    onResult: function(node, query, result, resultCount, resultCountPerGroup) { 
     if (resultCount < 1) { 
     //must reset current element here 
     } 
    } 
    } 
}); 

편집

을 위해 그것을 피하기 위해 같은 것

$('#vehicleParamTable tr td:first-child')

좋은 보이지만, 정의되지 않은

를 돌려 나머지 (선행 입력 초기화 ..)와

편집 2 동적으로 행을 추가했기 때문에 입력 헤드를 새로 고침해야합니다 ...

답변

1

이 글자는 https://github.com/running-coder/jquery-typeahead을 사용하고 있다고 가정합니다.

이 플러그인은 입력 필드에서 초기화해야합니다. 입력 필드가 헤더 다음 첫 번째 행의 첫 번째 열에있는 경우 선택자는

$('#vehicleParamTable tbody tr td:first-child input').typeahead({ ...options }) 
관련 문제