![在这里插入图片描述](https://img-blog.csdnimg.cn/20191121231236797.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1hfc2FnYWNpb3Vz,size_16,color_FFFFFF,t_70)
添加
function showModel() {
$("#myModal").modal("show");
$("#modal_footer").html("<button type=\"button\" οnclick='addArticle()' class=\"btn btn-primary\">保存</button>\n" +
"<button type=\"button\" class=\"btn btn-danger\" data-dismiss=\"modal\">取消</button>");
KindEditor.create('#editor',{
uploadJson:"${pageContext.request.contextPath}/kindeditor/upload",
filePostName:"img",
fileManagerJson:"${pageContext.request.contextPath}/kindeditor/getAllImg",
allowFileManager:true,
afterBlur:function () {
this.sync();
}
});
$("#addArticleFrom")[0].reset();
KindEditor.html("#editor","");
}
function addArticle() {
$.ajax({
url:"${pageContext.request.contextPath}/article/add",
datatype:"json",
type:"post",
data:$("#addArticleFrom").serialize(),
success:function (data) {
$("#myModal").modal("toggle");
$("#articleList").trigger("reloadGrid");
}
})
}
修改+数据回显
function editArticle(id) {
$("#addArticleFrom")[0].reset();
$("#myModal").modal("show");
var data = $("#articleList").getRowData(id);
$("#title").val(data.title);
$("#author").val(data.author);
$("#status").val(data.status);
KindEditor.create('#editor',{
uploadJson:"${pageContext.request.contextPath}/kindeditor/upload",
filePostName:"img",
fileManagerJson:"${pageContext.request.contextPath}/kindeditor/getAllImg",
allowFileManager:true,
afterBlur:function () {
this.sync();
}
});
KindEditor.html("#editor",null);
KindEditor.appendHtml("#editor",data.content);
$("#modal_footer").html("<button type=\"button\" οnclick=\"updateArticle('"+id+"')\" class=\"btn btn-primary\">保存</button>\n" +
"<button type=\"button\" class=\"btn btn-danger\" data-dismiss=\"modal\">取消</button>");
}
function updateArticle(id) {
$.ajax({
url:"${pageContext.request.contextPath}/article/update?id="+id,
datatype:"json",
type:"post",
data:$("#addArticleFrom").serialize(),
success:function (data) {
$("#myModal").modal("toggle");
$("#articleList").trigger("reloadGrid");
}
})
}
删除
function deleteArticle(id) {
$.ajax({
url:"${pageContext.request.contextPath}/article/delete?id="+id,
type:"post",
datatype:"json",
success:function (data) {
$("#articleList").trigger("reloadGrid");
}
})
}