将insert方法分离,不再批量操作,点一次保存一次:
//添加节点
function append() {
if (endEditing()){
var uid=uuid();//使用uuid作为新记录的自定义id
var node = $('#tg').treegrid('getSelected');
var parentId = null; if(node){ parentId=node.id;}
$('#tg').treegrid('append', { parent : parentId, data : [ { id : uid, name : '' } ] });
$.ajax({
type:"post",
url:"/insertOne",
async: false,
data: {parentId:parentId,id:uid,name:''},
dataType:"json",
success: function(result){
},error: function (XMLHttpRequest, textStatus, errorThrown) {
$.messager.alert('提示', '保存失败,ajax访问失败');
}
});
}
}