我使用 jTable 来显示 CD 信息,并使用一个子表来显示对该 CD 的评论。我希望能够只在登录用户的行上显示编辑\删除按钮。我一直在尝试遵循以下建议:https://github.com/hikalkan/jtable/issues/113
https://github.com/hikalkan/jtable/issues/893
https://github.com/hikalkan/jtable/issues/620
老实说,我对这些例子都不太满意。我们被告知在我们的作业中包含一些 jquery,所以我选择将它用于我的表数据。我希望现在我只是做了一些非常基本的事情!
无条件工作 jTable:
display: function (reviewData) {
//Create an image that will be used to open child table
var $img = $('<img class="child-opener-image" src="/Content/images/Misc/list_metro.png" title="List Reviews" />');
//Open child table when user clicks the image
$img.click(function () {
$('#ReviewTableContainer').jtable('openChildTable',
$img.closest('tr'),
{
title: "Your reviews on this album",
actions: {
listAction: 'childReviewActions.php?action=list&ID=' + reviewData.record.CDID,
deleteAction: 'childReviewActions.php?action=delete&ID=' + reviewData.record.CDID,
updateAction: 'childReviewActions.php?action=update&ID=' + reviewData.record.CDID
},
fields: {
userID: {
key: true,
create: false,
edit: false,
list: false
},
userName: {
title: 'User',
edit: false,
width: '20%'
},
reviewDate: {
title: 'Review date',
width: '20%',
type: 'date',
edit: false,
displayFormat: 'dd-mm-yy'
},
reviewText: {
title: 'Review',
type: 'textarea',
width: '40%'
}
},
问题 620 尝试:
actions: {
listAction: 'childReviewActions.php?action=list&ID=' + reviewData.record.CDID,
@if (reviewData.record.userID == <?php echo mysql_real_escape_string($_SESSION['ID']);?>)
{
deleteAction: 'childReviewActions.php?action=delete&ID=' + reviewData.record.CDID,
updateAction: 'childReviewActions.php?action=update&ID=' + reviewData.record.CDID
}
},
这种方式给我编译错误:IF 语句上的属性 ID 无效。 如果我在 if 语句中取出 @,我会得到:missing : after property id。
问题 113 和 893 尝试:
actions: {
listAction: {
url:'http://localhost/childReviewActions.php?action=list&ID=' + reviewData.record.CDID
//updateAction: {
//url:'childReviewActions.php?action=update&ID=' + reviewData.record.CDID,
//enabled: function (data) {
//return data.record.userID = <?php echo mysql_real_escape_string($_SESSION['ID']);?>;
//}
//}
},
在这一点上,我什至无法让它列出子表的内容。它不断返回 404 not found 错误:在此服务器上找不到请求的 url/[object object]。有没有人有任何想法如何让这些例子工作有一个不同的例子如何让表格启用\启用编辑,更新按钮?这对我来说是全新的,所以我现在道歉
最佳答案
rowInserted: function (event, data) {
//After child row loads. Check if the review belongs to the member logged in. If not remove the edit/delete buttons
if (data.record.userID != $user) {
data.row.find('.jtable-edit-command-button').hide();
data.row.find('.jtable-delete-command-button').hide();
}
else{
//If a review record does belong to the user set variable to true so the add new review link can be hidden after all records have been loaded
$memberReviewExists = true;
//Also needed here for when a new record is inserted
$(".jtable-add-record").hide();
}
},
recordsLoaded: function (event, data) {
if (typeof $memberReviewExists != 'undefined' && $memberReviewExists == true){
$(".jtable-add-record").hide();
$memberReviewExists = null;
}
else {
//No review currently exists for this user so show the Add review link $(".jtable-add-record").show();
}
},
recordDeleted: function (event, data) {
//User has deleted their review. Re-show the add new review link
$(".jtable-add-record").show();
}
关于javascript - jTable 条件显示\隐藏基于数据所有者的编辑和删除按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20542099/