Javascript jTable Conditional show \根据数据所有者隐藏编辑和删除按钮

Javascript jTable Conditional show \根据数据所有者隐藏编辑和删除按钮,javascript,jquery,jtable,Javascript,Jquery,Jtable,Im使用jTable显示CD信息,并使用子表显示对该CD的评论。我希望能够仅显示登录用户行上的编辑\删除按钮。我一直在努力遵循以下建议: 老实说,我在这些例子中运气都不好。我们被告知在作业中包含一些jquery,所以我选择将其用于我的表数据。我希望现在我只是做了一些非常基本的事情 无条件工作: display: function (reviewData) { //Create an image that will be used to open chi

Im使用jTable显示CD信息,并使用子表显示对该CD的评论。我希望能够仅显示登录用户行上的编辑\删除按钮。我一直在努力遵循以下建议:

老实说,我在这些例子中运气都不好。我们被告知在作业中包含一些jquery,所以我选择将其用于我的表数据。我希望现在我只是做了一些非常基本的事情

无条件工作:

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%'
                                        }
                                    },
显示:功能(查看数据){
//创建将用于打开子表的映像
var$img=$('');
//当用户单击图像时打开子表
$img.单击(函数(){
$('#ReviewTableContainer').jtable('openChildTable',
$img.最近('tr'),
{
标题:“你对这张专辑的评论”,
行动:{
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
},  
字段:{
用户标识:{
关键:没错,
创建:false,
编辑:false,
列表:false
},
用户名:{
标题:“用户”,
编辑:false,
宽度:“20%”
},
回顾:{
标题:“审查日期”,
宽度:“20%”,
键入:“日期”,
编辑:false,
显示格式:“dd-mm-yy”
},
复习课文:{
标题:"检讨",,
键入:“textarea”,
宽度:“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
    }
},
操作:{
listAction:'childReviewActions.php?action=list&ID='+reviewData.record.CDID,
@如果(reviewData.record.userID==)
{
deleteAction:'childReviewActions.php?action=delete&ID='+reviewData.record.CDID,
updateAction:'childReviewActions.php?action=update&ID='+reviewData.record.CDID
}
},
这样就产生了编译错误:IF语句上的属性id无效。 如果在If语句中去掉@,则在属性id之后得到:missing:

问题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']);?>;
        //}
    //}
},                                      
操作:{
清单行动:{
网址:'http://localhost/childReviewActions.php?action=list&ID='+reviewData.record.CDID
//更新操作:{
//url:'childReviewActions.php?action=update&ID='+reviewData.record.CDID,
//已启用:功能(数据){
//返回data.record.userID=;
//}
//}
},                                      

在这个问题上,我甚至无法让它列出子表的内容。它不断返回404 not found错误:请求的url/[object]在此服务器上找不到。是否有人知道如何使用这些示例?是否有其他示例说明如何获取表格以启用\启用编辑、更新按钮?这对我来说是全新的,因此我现在向您道歉。@Toni您的代码也包含asp.net代码。
@
是asp.net吗.NET指令。

以下操作对我有效。它隐藏了当前用户不是授权用户的行上的编辑/删除按钮。注意:我在mysql表中为authorizedUser添加了一列,并使用该列来了解是否允许该用户

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();

                                    }
rowInserted: function(event, data){
     var $currentUser='<?php echo $_SESSION['email']?>';
     if (data.record.authorizedUser != $currentUser) {
        data.row.find('.jtable-edit-command-button').hide();
        data.row.find('.jtable-delete-command-button').hide();
     }
  },
rowserted:函数(事件、数据){
var$currentUser='';
if(data.record.authorizedUser!=$currentUser){
data.row.find('.jtable编辑命令按钮').hide();
data.row.find('.jtable delete命令按钮').hide();
}
},

谢谢您回复我。不,我不应该使用asp。我以前从未使用过它,所以我没有注意到。我已经成功地使它工作,并将为希望使用此功能的任何其他人发布我的答案。这些函数是在jTables字段名称后插入的