【问题标题】:modal code is not working when appended through js in materialize在物化中通过 js 附加时,模态代码不起作用
【发布时间】:2018-02-21 10:16:36
【问题描述】:

我正在尝试通过单击图标打开模式。此图标由 js 在表格中生成,并带有相应的数据,但它不起作用

但是当我在 Blade.php 文件中复制粘贴相同的代码时,它工作正常。

我也附上截图。 希望能得到答案。

注意:使用 laravel

function actionFormatter(value, row, index) {
    	    if (row.status == '1') {


    	        return [
    	            
    	            '<a class="editGreenColor tooltipped modal-trigger"   data-tooltip="Edit" href="#modal5">',
    	            '<i title="Edit" class="mdi-content-create small fontSzie1pt5rm"></i>',
    	            '</a> ',
    	            
    	            
    	        ].join('');
    	    }
    	}
<table data-toolbar="#toolbar" class="table table-striped table-bordered bootstrap-table" data-unique-id="id" 	
data-toggle="table" data-url="{{url('/branches/')}}/{{ $prantId }}/get" style="font-size: 14px" data-filter-control="true" data-row-style="rowStyle" 
id="branchTable" data-pagination="true">
<thead>
  <tr>
   <th data-field="id" data-align="center" data-width="5%" data-sortable="true">ID</th>
   
   <th id="name" data-field="name" data-width="25%" data-sortable="true" data-formatter="allBranchViewFormatter">Name</th>

   <th data-field="id" data-formatter="actionFormatter" >Actions</th>
 </tr>
</thead>
</table>










<div id="modal5" class="modal bottom-sheet">

// some codes

</div>

screenshot1

screenshot2

【问题讨论】:

    标签: javascript modal-dialog materialize


    【解决方案1】:

    您必须自己初始化模态。检查http://materializecss.com/modals.html#initialization

    【讨论】:

    • 我试过了,不行。是因为它正在附加数据吗?
    • 在添加锚点后初始化模态框了吗?
    • 我没听懂你,你能解释一下吗?我是编程新手。
    • 您是以编程方式添加锚点,因此您应该在最后一次调用actionFormatter函数后初始化模态
    • @cris 解决了这个问题,我已经评论了我的答案。谢谢你的帮助。如果您有更好的解决方案,请举例说明:)
    【解决方案2】:

    我通过添加 onClick 函数解决了这个问题,感谢@cris 的帮助

    function openEdit() {
    
      $(".modal").openModal()
    }
    <a class="editGreenColor tooltipped modal-trigger" data-tooltip="Edit" href="javascript:void(0)" onclick="openEdit()">
      <i title="Edit" class="mdi-content-create small fontSzie1pt5rm"></i>

    【讨论】:

      猜你喜欢
      • 2018-08-14
      • 2018-02-16
      • 2018-02-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-06
      • 2017-04-21
      • 2017-06-17
      相关资源
      最近更新 更多