1.关于新增与编辑
this.add = function() {
var selection = tree.tree('getSelected');
var treeId = selection.id;
var treeName = selection.text;
addDialog = $.topDialog({
title:'新增',
iconCls:'icon-save',
href:addWinPath,
width : 800,
height : 400,
resizable : true,
modal : true,
onClose:function(){
addDialog = undefined;
tempRec = undefined;
editDialog = undefined;
},
onLoad:function(){
//给隐藏的区域ID赋值
addDialog.find('[name="areaid"]').val(treeId);
addDialog.find('[name="areaname"]').val(treeName);
},
buttons:[{
text:'保存',
handler:function(){
if(undefined == tempRec && null == tempRec){
addDialog.find('.dialog-button .l-btn:first-child').linkbutton('disable');
saveForminfo('new',addDialog);
}else{
editSave();
}
}
},{
text:'关闭',
handler:function(){
if(editDialog){
$.topDialog('close',editDialog);
}
if(addDialog){
$.topDialog('close',addDialog);
}
}
}]
});
}
$.topDialog重要属性说明及注意事项:
onClose:窗口关闭(右上角×)事件,在此事件中可以添加清除数据操作,防止多次弹出窗口时会出现因缓存等原因产生数据混淆;注:jQuery EasyUI的此默认方法是将窗口隐藏而非移除!
onLoad:窗口加载时渲染事件,在此事件中可以进行窗口数据初始化操作;编辑时的数据回填就是在此事件中editDialog.find('form').form('load', record);
2.Ajax使用
$.ajax({
url: contextPath + '/mvc/xxx/xyyyy/zzzz/service/tree',
data:{'id':node.id},
success:function(nodes){
if(nodes.length > 0){
$('.add_button').linkbutton('disable');
}else{
$('.add_button').linkbutton('enable');
}
grid.datagrid('load', {areaid:node.id});
}
});
@RequestMapping("/xxx/xyyyy/zzzz")
/**
* 树节点查询
*
* @param param
* 前台相关参数
* @return 当前页面记录
*/
@RequestMapping("/service/tree")
@ResponseBody
public List<TreeModel<T>> tree(String id, String root) {
if (StringUtils.isNotBlank(root) && StringUtils.isBlank(id)) {
// 包含当前节点
return new TreeView(service.listTreeRoot(root)).convertTree();
} else {
// 子节点
String isAble = "";//机构状态
return new TreeView(service.listTreeById(id, isAble, null)).convertTree();
}
}
属性说明:
url:后台请求路径,该示例基于Spring和MyBatis框架,路径注意与后台RequestMapping对应;
data:参数集合;
success:回调函数