Kindeditor和模态框结合添加修改数据

1 篇文章 0 订阅

在这里插入图片描述

添加

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);
        // if (data.status=="展示"){
        //     $("#status").val("展示");
        // }else {
        //     $("#status").val("不展示");
        // }
        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");
            }
        })
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值