Typeahead 和第一个单元格选择器

Typeahead and first cell selector

我有这个table

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

当点击 link 时,我添加了一行。工作正常。

在该行的第一列中,我添加了一个 jquery-typehead

选择器不工作,也想在第一行避免它(th header)

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

看起来不错,但是 return 未定义

编辑2因为我是动态添加行,需要刷新打字头...

我假设你正在使用这个 https://github.com/running-coder/jquery-typeahead?

此插件需要在输入字段上初始化。 因此,假设您的输入字段位于 header 之后第一行的第一列,选择器将是

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