Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/471.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_Twitter Bootstrap_Twitter Bootstrap 3_Bootstrap Table - Fatal编程技术网

Javascript 如何将引导模式绑定到使用引导表呈现的操作按钮

Javascript 如何将引导模式绑定到使用引导表呈现的操作按钮,javascript,twitter-bootstrap,twitter-bootstrap-3,bootstrap-table,Javascript,Twitter Bootstrap,Twitter Bootstrap 3,Bootstrap Table,我想使用由我添加到引导表中的操作按钮触发的引导模式,但我想不出来。有没有办法将这些按钮的数据属性绑定到模式?在这种情况下不起作用。或者,如果我只能通过javascript来实现,我该如何实现呢?因为在我的情况下,它也不起作用。无论哪种方式都不会抛出错误 这是一个屏幕截图,以明确我所说的按钮:每行上的编辑和删除按钮 我使用的代码是: // Click handler for the edit button when I try the data attributes way function o

我想使用由我添加到引导表中的操作按钮触发的引导模式,但我想不出来。有没有办法将这些按钮的数据属性绑定到模式?在这种情况下不起作用。或者,如果我只能通过javascript来实现,我该如何实现呢?因为在我的情况下,它也不起作用。无论哪种方式都不会抛出错误

这是一个屏幕截图,以明确我所说的按钮:每行上的编辑和删除按钮

我使用的代码是:

// Click handler for the edit button when I try the data attributes way
function operateFormatter(value, row, index) {
    return [
        '<a class="edit ml10" href="#dialogo-destinos" data-toggle="modal"  title="Edit">',
            '<i class="glyphicon glyphicon-edit"></i>',
        '</a>',
        '<a class="remove ml10" href="javascript:void(0)" title="Remove">',
            '<i class="glyphicon glyphicon-remove"></i>',
        '</a>'
    ].join('');
}
// Code for the javascript way:
window.operateEventsDestinos = {
    'click .edit': function (e, value, row, index) { 
        var $dialogo = $('.dialogo.destinos');
        ... // actions to populate the modal according to the row data
        $dialogo.modal('show');
        ...
    },
    'click .remove': function (e, value, row, index) {
        ...
    }
};
//尝试数据属性方式时,单击“编辑”按钮的处理程序
函数运算符格式(值、行、索引){
返回[
'',
''
].加入(“”);
}
//javascript方式的代码:
window.operateEventsDestinos={
'click.edit':函数(e、值、行、索引){
变量$dialogo=$('.dialogo.destinos');
…//根据行数据填充模式的操作
$dialogo.modal('show');
...
},
“click.remove”:函数(e、值、行、索引){
...
}
};
由引导表呈现的表:

<div class="row">
    <div class="col-md-12">
        <table id="tabla-datos-destinos" class="bootstrap-table table table-striped table-hover"
                data-pagination="true" data-search="true" data-show-header="true"
                data-show-columns="true" data-show-refresh="true" data-toolbar="#custom-toolbar"
                data-show-toggle="true" data-show-export="true">
           <thead>
                <tr>
                    <th data-field="nombre" data-sortable="true">Nombre</th>
                    <th data-field="poblacion" data-sortable="true">Localidad</th>
                    <th data-field="provincia" data-sortable="true">Provincia</th>
                    <th data-field="operate" data-formatter="operateFormatter" data-events="operateEventsDestinos">Acciones</th>
                </tr>
           </thead>
        </table>
    </div>
</div>

名义
地方爸爸
省
疫苗
当然还有模态的HTML:

<div class="dialogo destinos modal fade" id="dialogo-destinos">
...
</div>

...
你知道为什么这样不行吗?或者我该怎么办

编辑:


我也试着用按钮代替标签,但我也不能让它工作。而是运行默认行为:提交表单。有没有办法直接在表的HTML中添加操作按钮,而不必通过javascript添加它们,我认为这就是绑定没有完成的原因?

您可以简单地将
数据切换
数据目标
绑定到
acciones
div中的按钮上

例如:

<!-- Button trigger modal -->
<button type="button" class="btn btn-primary btn-sm" data-toggle="modal" data-target="#dialogo-destinos">
  Launch Modal
</button>

发射模态

请注意,我已经在用一个标签做这件事了。请参阅操作列的operateformatter处理程序。它不必是按钮标记,也可以是a标记,重要的是将
数据切换
数据目标
绑定到您的模式中。如果我将
数据目标=“#dialogo destinos”
添加到标记中,尽管我认为在
href
属性中这样做就足够了,但这两种方式都不会发生任何事情:(而且,我必须使用绑定到列的此函数来显示操作按钮(在本例中为链接)。