<body style="visibility: visible;"> <table id="menuview" idField="menuId" rownumbers="true" pagination="true" fitColumns="true" singleSelect="false" pageSize="15" pageList="[15,30,45,60]" toolbar="#tb" url="${pageContext.request.contextPath }/menu/list.action" > <thead> <tr> <th field="menuId" width="50" align="center" checkbox="true"></th> <th field="name" width="80" align="center" >按鈕名稱</th> <th field="actionURL" width="80" align="center" >按鈕URL</th> <th field="parentMenu" width="80" align="center" >上級按鈕</th> <th field="modify" align="center" width="50" formatter="rowFormater" align="center">操作</th> </tr> </thead> </table> <div id="tb"> <a href="${pageContext.request.contextPath }/menu/addMenu.jsp" class="easyui-linkbutton" iconCls="icon-add" plain="true">新增</a> <a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="javascript:delData();">刪除</a> </div> </body>
function rowFormater(value, row, index) { return '<a href="javascript:void(0)" onclick="showMessageDialog('+ row.menuId+');">設置</a>'; } //url:窗口調用地址,title:窗口標題,width:寬度,height:高度,shadow:是否顯示背景陰影罩層 function showMessageDialog(id) { url="${ctx}/menu/menuManage.jsp?id="+id; title="設置"; shadow=true; var content = '<iframe id="menuAdminManage" src="' + url + '" width="100%" height="99%" frameborder="0" scrolling="no"></iframe>'; var boarddiv = '<div id="msgwindow" title="' + title + '"></div>'; //style="overflow:hidden;"可以去掉滾動條 $(document.body).append(boarddiv); var win = $('#msgwindow').dialog({ content: content, width: "700px", height: "500px", modal: shadow, title: title, onClose: function () { $(this).dialog('destroy');//后面可以關閉后的事件 } }); win.dialog('open'); }
iframe的傳值問題的解決
function geturl(name) { var reg = new RegExp("[^\?&]?" + encodeURI(name) + "=[^&]+"); var arr = window.parent.document.getElementById("menuAdminManage").contentWindow.location.search.match(reg); if (arr != null) { return decodeURI(arr[0].substring(arr[0].search("=") + 1)); } return ""; }
根據documentation的描述,formatter的格式化函數有3個parameters,分別是:
value: the field value,也就是field:'id'。rowData: the row record data。
就是這一行的Json數據,包括你已經選擇在Datagrid上顯示的內容,和沒顯示的內容。
因為我的Json數據里包括了Id這一內容,所以我可以直接調用。如果你作為數據源的Json里沒有Id屬性,需要修改一下Json的輸出。
我的每行Json輸出是類似{"id":"1","name":"\u7ecf\u6d4e\u53d1\u5c55","parentId":"0"}的結構
rowIndex: the row index.當前行的Index。