Javascript 尝试在表上创建查找器时出错
我正在尝试替换django中的jquery应用程序,我正在尝试使用stimulus js,因为它与turbolink一起使用似乎是一个不错的选择,但我在创建数据表时遇到了一个问题,在搜索引擎中输入文本时,它会正确执行,并返回我编写的内容,但问题出在表中,因为浏览器控制台返回未定义的值。 这是我的html:Javascript 尝试在表上创建查找器时出错,javascript,stimulusjs,Javascript,Stimulusjs,我正在尝试替换django中的jquery应用程序,我正在尝试使用stimulus js,因为它与turbolink一起使用似乎是一个不错的选择,但我在创建数据表时遇到了一个问题,在搜索引擎中输入文本时,它会正确执行,并返回我编写的内容,但问题出在表中,因为浏览器控制台返回未定义的值。 这是我的html: <div data-controller="search"> <input type="text
<div data-controller="search">
<input type="text" placeholder="Buscar..." maxlength="15" data-action="search#searchTable"data-search-target="q">
<table class="highlight centered">
<thead>
<tr>
<th>Tipe de Tarea</th>
<th>Estado</th>
<th>Fecha de Creacion</th>
<th>Accion</th>
</tr>
</thead>
<tbody>
<tr>
{% for field in object_list %}
<td data-search-target="name">{{ field.name }}</td>
<td>{{ field.status|yesno:"Visible, No visible" }}</td>
<td>{{ field.created_at }}</td>
<td>
<a href="#!">editar</a>
</td>
{% endfor %}
</tr>
</tbody>
</table>
</div>
我认为你把目标搞乱了
q
是输入,将有一个值name
是一个表单元格,因此只有innerHTML
。相反,它应该是:
searchTable() {
console.log(this.qTarget.value);
}
但我建议您进一步将事件传递给searchTable函数。这样,您就不需要在输入端设置数据目标
searchTable(e) {
console.log(e.srcElement.value);
}
searchTable(e) {
console.log(e.srcElement.value);
}