首页 \ 问答 \ 隐藏的Bootstrap模式不会触发(Bootstrap modal on hidden does not trigger)

隐藏的Bootstrap模式不会触发(Bootstrap modal on hidden does not trigger)

就像标题所说我有问题要运行modal.on('hidden')事件。 我可以毫无问题地打开模态。 使用它的代码看起来像这样:

var info = $('<img src="img/icons/info.png">');
info.attr('data-toggle','modal');
info.attr('data-target','#infoPopup');

模态本身看起来像这样:

 <div class="modal fade" id="infoPopup" role="dialog">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">&times;</button>
                <h4 id="popupHeader" class="modal-title"></h4>
            </div>
            <div id="popupBody" class="modal-body">
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            </div>
        </div>
    </div>
</div>

它开得很好但是当我通过点击模式旁边的关闭按钮或右上角的X来关闭它时,似乎隐藏的事件不是触发器。

$('.modal.in').on('hidden',function(){
            console.log('test');
        });

当我尝试使用$('.modal.in')在控制台上访问它时,所选的模态是正确的。 所以我不是想在错误的模态上得到一个回调。 我也尝试用$('.modal.in').on('hidden.bs.modal',func...) 。 但我得到了同样的结果。

谢谢你的帮助。


Like the title says i have problem to getting the modal.on('hidden') event to run. I can open the modal without any problems. The code im using for it looks something like this:

var info = $('<img src="img/icons/info.png">');
info.attr('data-toggle','modal');
info.attr('data-target','#infoPopup');

The modal itself looks like this:

 <div class="modal fade" id="infoPopup" role="dialog">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">&times;</button>
                <h4 id="popupHeader" class="modal-title"></h4>
            </div>
            <div id="popupBody" class="modal-body">
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            </div>
        </div>
    </div>
</div>

It Opens perfectly fine but it seems like the hidden event is not triggert when I'm closing it by clicking beside the modal the close button or the X on the top right.

$('.modal.in').on('hidden',function(){
            console.log('test');
        });

The selected modal is the correct one when i'm trying to access it on the console with $('.modal.in'). So i'm not trying to get a callback on the wrong modal. I also tried it with $('.modal.in').on('hidden.bs.modal',func...). But i got the same result.

Thanks for your help.


原文:https://stackoverflow.com/questions/35454352
更新时间:2023-07-05 22:07

最满意答案

您可以通过获取第一个值来聚合名称。

In [283]: df.groupby('email').agg({'price': sum, 'quantity': sum, 'name': 'first'
     ...: })
Out[283]:
         price     name  quantity
email
a@a.com   5.30     alan         2
b@a.com   4.99  barbara         2

或者,您可以将名称聚合成一个字典。

In [281]: df.groupby('email').agg({'price': sum, 'quantity': sum, 'name': lambda x
     ...: : x.value_counts().to_dict()})
Out[281]:
         price             name  quantity
email
a@a.com   5.30     {u'alan': 1}         2
b@a.com   4.99  {u'barbara': 2}         2

或者,如果您要添加为字符串。

In [282]: df.groupby('email').agg({'price': sum, 'quantity': sum, 'name': sum })
Out[282]:
         price            name  quantity
email
a@a.com   5.30            alan         2
b@a.com   4.99  barbarabarbara         2

但是,对于您的电子邮件名称组合相同的特定情况,您可以使用Igor Raush的建议df.groupby(['name', 'email'], as_index=False).sum()


You could aggregate, names by taking the first value.

In [283]: df.groupby('email').agg({'price': sum, 'quantity': sum, 'name': 'first'
     ...: })
Out[283]:
         price     name  quantity
email
a@a.com   5.30     alan         2
b@a.com   4.99  barbara         2

Or, you could aggregate names into a dict.

In [281]: df.groupby('email').agg({'price': sum, 'quantity': sum, 'name': lambda x
     ...: : x.value_counts().to_dict()})
Out[281]:
         price             name  quantity
email
a@a.com   5.30     {u'alan': 1}         2
b@a.com   4.99  {u'barbara': 2}         2

Or, if you were looking to add as string.

In [282]: df.groupby('email').agg({'price': sum, 'quantity': sum, 'name': sum })
Out[282]:
         price            name  quantity
email
a@a.com   5.30            alan         2
b@a.com   4.99  barbarabarbara         2

But, for a specific case where your email-name combination is same, you can go with Igor Raush's suggestion df.groupby(['name', 'email'], as_index=False).sum()

相关问答

更多

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。