【问题标题】:popconfirm doesn't work in table (<td>)popconfirm 在表中不起作用 (<td>)
【发布时间】:2016-03-10 11:25:57
【问题描述】:

我在一个带有 playframework 的 scala 应用程序中工作,我想在智能表中使用 popover 确认,我为 popconfirm ("popconfirm":"0.4.3") 进行了安装,它运行良好,除了在表格中正好在&lt;td&gt;

我的代码中有一部分:

<table st-table="topics" st-safe-src="topicList" class="table table-striped">
    <thead>
        <tr>
            <th st-sort="domain">Domain</th>
            <th class="text-center">Actions</th>
        </tr>
    </thead>
    <tbody>
        <tr ng-repeat="topic in topics">
            <td>{{topic.domain}}</td>
            <td class="text-center">
                <div class="btn-group btn-group-xs">
                    <a  href="javascript:void(0)" data-toggle="tooltip" data-original-title="Edit" class="btn btn-default" ng-click="showTopic(topic)" title><i class="fa fa-pencil"></i></a>

                    <button  href="" type="submit" data-toggle="tooltip" data-original-title="Remove" class="btn btn-danger popconfirm" ng-click="removeTopic(topic)" title><i class="hi hi-remove"></i>
                    </button>
                    <button type="submit" class="btn btn-success popconfirm" href="@routes.Application.index()">Test</button>  
                </div>           
            </td>
                    <button type="submit" class="btn btn-success popconfirm" href="@routes.Application.index()">Work</button>
        </tr>
    </tbody>
</table>
    <script src="@routes.Assets.versioned("temp/js/vendor/jquery-1.12.0.min.js")"></script>
    <script type="text/javascript">

        $(document).ready(function() {
            $(".popconfirm").popConfirm();  
        });
    </script>

确认按钮“工作”运行良好,但测试不起作用,请帮忙?

【问题讨论】:

    标签: jquery html angularjs twitter-bootstrap popover


    【解决方案1】:

    上面的代码不起作用,因为它在渲染ng-repeat(它延迟渲染内容)内容之前调用了$(".popconfirm").popConfirm();方法。所以它什么都不做。

    为了解决该问题,您需要创建一个指令,该指令将在该 button 上启用 popConfirm 功能,一旦它被 ng-repeat 渲染。您可以使用指令link 函数来获取角度编译的element 来调用它的popConfirm() 方法。

    指令

    app.directive('popconfirm', function(){
      return {
        restrict: 'C',
        link: function(scope, element){
          element.popConfirm();
        }
      }
    })
    

    【讨论】:

    • 非常感谢您的帮助,它的工作,但我不得不添加这样的回报: app.directive('popconfirm', function(){ return { restrict: 'C', link:函数(范围,元素){ element.popConfirm(); } }; });
    • 那是我的错……很高兴能帮助你……谢谢 ;)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-03-21
    • 1970-01-01
    • 2018-11-25
    • 1970-01-01
    • 1970-01-01
    • 2017-03-03
    • 2012-12-14
    相关资源
    最近更新 更多