2017-10-16 73 views
1

我有這個表和事先鍵入的內容第一個單元格選擇

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

當一個鏈接的點擊,我添加一行。這很好。

在該行的第一列中,我添加的jquery-typehead

選擇器不工作,也想避免它爲第一行(th頭)

$('#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')

似乎不錯,但與返回undefined

其餘的(預輸入初始化..)

編輯2因爲我動態添加行,需要刷新打字頭...

回答

1

我假設你正在使用這個https://github.com/running-coder/jquery-typeahead

這個插件需要在輸入字段上初始化。 因此,鑑於您的輸入字段在標題之後的第一行的第一列中,選擇器將是

$('#vehicleParamTable tbody tr td:first-child input').typeahead({ ...options }) 
相關問題