layui富文本(layui.layedit )无初始值时的取值问题

layui富文本(layui.layedit )无初始值时的取值

1.使用框架自带方法

form.on('submit(url_form)', function (data) {
            // layedit.sync(index);
            $("#content").attr("value",layedit.getContent(index));
            data.field.picDescribe = layedit.getContent(index);
            var id = $("#id").val();
            if (id!=='') {
                $.ajax({
                    url: '/cycle',
                    type: 'PUT',
                    async: false,
                    dataType: 'json',
                    data: data.field,
                    success: function (result) {
                        if (result.success) {
                            layer.closeAll();
                            parent.layui.table.reload('list_table');//刷新父元素列表
                            layer.msg("保存成功");
                        } else {
                            layer.msg("保存失败");
                        }
                    }
                });
            }else {
                $.ajax({
                    url: '/cycle',
                    type: 'POST',
                    async: false,
                    dataType: 'json',
                    data: data.field,
                    success: function (result) {
                        if (result.success) {
                            layer.closeAll();
                            parent.layui.table.reload('list_table');
                            layer.msg("保存成功");
                        } else {
                            layer.msg("保存失败");
                        }
                    }
                });
            }
            return false;
        });

2,提前触发同步
layedit.sync(index);只有在form.on(‘submit(url_form)’, function (data) {}流程走完才会完成同步操作,所以在此流程中同步是无效的

$(".layui-btn").click(function () {
    layedit.sync(index);
})
//或者使用鼠标焦点离开事件触发
form.on('submit(url_form)', function (data) {
            // layedit.sync(index);
            $("#content").attr("value",layedit.getContent(index));
            data.field.picDescribe = layedit.getContent(index);
            var id = $("#id").val();
            ......................
 }
 $("#msg_add").click(function () {
            showDialog({
                title: '添加',
                template: '/views/photogame/grab/template/add.html',
                height: 750,
                yes:function (index,layero) {
                    if(form.validate()==null){
                        var d = {};
                        var activityType = $(layero).find("select").val();
                        ..................................
                        //弹窗可以在此触发
                }
             }
}

你可能感兴趣的:(前端)