【问题标题】:Typeahead and first cell selector预输入和第一个单元格选择器
【发布时间】:2017-10-16 15:03:48
【问题描述】:

我有这张桌子

<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')

看起来不错,但是其余的(typeahead init..)返回未定义

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

【问题讨论】:

    标签: javascript jquery typehead


    【解决方案1】:

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

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

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

    【讨论】:

      猜你喜欢
      • 2014-09-07
      • 1970-01-01
      • 2012-01-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-20
      • 2010-11-28
      • 1970-01-01
      相关资源
      最近更新 更多