![](/img/trans.png)
[英]How do I get specific data from my localstorage so I can show them in a modal in JavaScript?
[英]How do I transfer the data-row-id from my formatter to my modal so I can process the proper record
data-row-id = \\“” + row.id +“ \\”正在工作,因為我可以看到html中顯示了data-row-id。 如何將data-row-id中的值獲取到PHP變量中,以便刪除或編輯記錄? 模態工作正常,但是當單擊編輯按鈕或刪除按鈕時,我需要能夠將data-row-id傳輸到我的模態中進行處理。 這是我的表查找當前記錄的方式:
<script type="text/javascript">
$( document ).ready(function() {
//Basic Example
$("#data-table").bootgrid({
css: {
icon: 'zmdi icon',
iconColumns: 'zmdi-view-module',
iconDown: 'zmdi-expand-more',
iconRefresh: 'zmdi-refresh',
iconUp: 'zmdi-expand-less',
iconSearch: 'zmdi-search'
},
});
//Selection
$("#data-table-selection").bootgrid({
css: {
icon: 'zmdi icon',
iconColumns: 'zmdi-view-module',
iconDown: 'zmdi-expand-more',
iconRefresh: 'zmdi-refresh',
iconUp: 'zmdi-expand-less',
iconSearch: 'zmdi-search'
},
selection: true,
multiSelect: true,
rowSelect: true,
keepSelection: true
});
// Command Buttons
$("#data-table-command").bootgrid({
css: {
icon: 'zmdi icon',
iconColumns: 'zmdi-view-module',
iconDown: 'zmdi-expand-more',
iconRefresh: 'zmdi-refresh',
iconUp: 'zmdi-expand-less'
},
formatters: {
"commands": function (column, row) {
return "<button type=\"button\" class=\"btn btn-icon btn-primary command-edit\" data-toggle=\"modal\" data-target=\"#modalEdit\" data-row-id=\"" + row.id + "\"><span class=\"zmdi zmdi-edit\"></span></button> " +
"<button type=\"button\" class=\"btn btn-icon btn-danger command-delete\" data-toggle=\"modal\" data-target=\"#modalDelete\" data-row-id=\"" + row.id + "\"><span class=\"zmdi zmdi-delete\"></span></button>";
}
}
}).on("loaded.rs.jquery.bootgrid", function () {
/* Executes after data is loaded and rendered */
$(this).find(".command-edit").click(function (e) {
$($(this).attr("data-target")).modal("show");
});
}).on("loaded.rs.jquery.bootgrid", function () {
/* Executes after data is loaded and rendered */
$(this).find(".command-delete").click(function (e) {
$($(this).attr("data-target")).modal("show");
});
});
});
</script>
您可以使用$ _Get命令在數組中設置變量,您可以在此處找到更多信息: http : //php.net/manual/en/reserved.variables.get.php :
<?php
$row.id = $_GET['row.id'];
?>
我自己添加了以下內容:
var rowid = $(this).data('row-id');
至:
}).on("loaded.rs.jquery.bootgrid", function () {
/* Executes after data is loaded and rendered */
$(this).find(".command-edit").click(function (e) {
$($(this).attr("data-target")).modal("show");
var rowid = $(this).data('row-id');
});
現在要弄清楚如何將rowid中的值轉換為PHP值,以便我可以操作記錄...我假設我必須為此使用Ajax,但我不知道如何使用Ajax,請問有人可以救命? 謝謝!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.