【问题标题】:Show php data in data-formatter function of bootstrap-table在 bootstrap-table 的 data-formatter 函数中显示 php 数据
【发布时间】:2023-03-24 21:55:02
【问题描述】:

我在table.php 文件中创建了一个引导表,并使用这样的数据格式化程序定义了一个表标题

<th data-field='edit' data-formatter="editFormatter">Edit</th>

我为此创建了函数,

function editFormatter(value, row)
{
   return `<a href="<?= URL::to('xyz/label'); ?>"  ><i class="fa fa-pencil sg-edit-btn" ></i></a>`
}

但是当我检查 table.php 页面时,它显示的是这样的锚,

&lt;a href="&lt;?= URL::to('xyz/label'); ?&gt;

为什么php代码不能这样转换,

&lt;a href="https://localhost/app/public/xyz/label" class="btn sg-primary-btn"&gt;

有没有办法做到这一点?提前致谢

【问题讨论】:

  • 我试过了,但是不行,问题是PHP代码没有运行,
  • stackoverflow.com/questions/51176523/… - 希望这能解决你的问题:)
  • row.url 在我的情况下是 undefined
  • 用另一个文件试试我的答案示例
  • 客户端与服务器端?该函数是在 .php 文件中还是在 .js 文件中(不会被 PHP 解析)?

标签: javascript php html bootstrap-table


【解决方案1】:

var data = [{
  "url": "https://www.stackoverflow.com",
  "nice_name": "Stackoverflow"
}, {
  "url": "https://www.facebook.com",
  "nice_name": "Facebook"
}];

function linkFormatter(value, row) {
  return "<a href='" + row.url + "'>" + row.nice_name + "</a>";
}

$(function() {
  $('#table').bootstrapTable({
    data: data
  });
});
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
<script src="https://unpkg.com/bootstrap-table@1.14.2/dist/bootstrap-table.min.js"></script>

<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.3/css/all.css">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<link rel="stylesheet" href="https://unpkg.com/bootstrap-table@1.14.2/dist/bootstrap-table.min.css">

<table data-toggle="#table" id="table">
  <thead>
    <tr>
      <th data-field="url" data-formatter="linkFormatter" data-sortable="true">Link</th>
    </tr>
  </thead>
</table>

【讨论】:

    猜你喜欢
    • 2020-03-26
    • 2014-08-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-06
    • 2020-04-09
    • 2020-06-10
    • 2021-07-30
    相关资源
    最近更新 更多