popconfirm在table()中不起作用

时间:2016-03-10 11:25:58

标签: jquery html angularjs twitter-bootstrap popover

我正在使用playframework在scala应用程序中工作,我想在智能表中使用popover确认,我为popconfirm(“popconfirm”:“0.4.3”)进行了安装,但除了表格正好在<td> enter image description here

我的代码中有一部分:

<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>

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

1 个答案:

答案 0 :(得分:1)

上面的代码无效,因为它在呈现$(".popconfirm").popConfirm();(它呈现内容懒惰)内容之前调用ng-repeat方法。所以它什么都不做。

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

<强>指令

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