Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/459.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 尝试在表上创建查找器时出错_Javascript_Stimulusjs - Fatal编程技术网

Javascript 尝试在表上创建查找器时出错

Javascript 尝试在表上创建查找器时出错,javascript,stimulusjs,Javascript,Stimulusjs,我正在尝试替换django中的jquery应用程序,我正在尝试使用stimulus js,因为它与turbolink一起使用似乎是一个不错的选择,但我在创建数据表时遇到了一个问题,在搜索引擎中输入文本时,它会正确执行,并返回我编写的内容,但问题出在表中,因为浏览器控制台返回未定义的值。 这是我的html: <div data-controller="search"> <input type="text

我正在尝试替换django中的jquery应用程序,我正在尝试使用stimulus js,因为它与turbolink一起使用似乎是一个不错的选择,但我在创建数据表时遇到了一个问题,在搜索引擎中输入文本时,它会正确执行,并返回我编写的内容,但问题出在表中,因为浏览器控制台返回未定义的值。 这是我的html:

<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);
}