在springMVC项目中,从后台获取zTree的setting配置的方法为:
@RequestMapping("/getSetting")
public @ResponseBody String getSetting() {
String setting = "{view: {addHoverDom: addHoverDom,removeHoverDom: removeHoverDom,selectedMulti: false},"
+ "data: {simpleData: {enable: true}},"
+ "edit: {enable: true,showRemoveBtn: function(treeId, treeNode) {return treeNode.isParent ? false : true;},"
+ "showRenameBtn: function(treeId, treeNode) {return treeNode.level > 0 ? true : false;},"
+ "drag: {inner: false}}}";
return setting;
}
前端js中使用ajax访问后台并处理返回结果:
var setting = null;
$.ajax({
url: '/springmvc-mybatis/getSetting',
async: false,//使用同步操作,否则init方法执行时setting可能还未被赋值
success: function(data) {
setting = eval("("+ data +")");
}
});
$.fn.zTree.init($("#treeDemo"), setting, zNodes);
与http://blog.csdn.net/qq_25816185/article/details/64919481结合阅读。