javascript - 在 bootstrap-table 的 data-formatter 函数中显示 php 数据
问题描述
我在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
页面上检查时,它显示的是这样的锚点,
<a href="<?= URL::to('xyz/label'); ?>
为什么php代码不能像这样转换,
<a href="https://localhost/app/public/xyz/label" class="btn sg-primary-btn">
有什么办法吗?提前致谢
解决方案
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>
推荐阅读
- java - 如何使用注释添加外键约束
- elixir - Elixir Arc - 如何访问上传的文件
- sql - Postgres 缺少由 WHERE 子句引起的表错误的 FROM 子句条目
- javascript - 在观察者回调中使用“this”
- c# - 如何在 .net 5 中仅将 AzureAd 用于区域(管理员)和根(用户)的常规身份
- sql - SQL:第 5:5 行:“c”列不明确
- node.js - Node JS 通过回调提交 hCaptcha 令牌
- .net - 使用 Azure 函数的 API 密钥身份验证
- swift - SwiftUI TextField 重置值并忽略绑定
- javascript - 将渐变字符串解析为颜色