2017-10-16 77 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 }) 
相关问题