首页 > 代码库 > layui的编辑器 layedit的异步赋值问题

layui的编辑器 layedit的异步赋值问题

layedit 需要先构建编辑器 再输出数据

如果取值 慢于 构建编辑器  那么数据在编辑器中就无法显示了

layui.use(‘layedit‘,function() {
var layedit = layui.layedit;

//构建一个默认的编辑器
var index = layedit.build(‘LAY_demo1‘);
});

//js本地赋值
$(document).ready(function() {
var $title1 = $("#newsTitle_1");
var $content1 = $("#LAY_demo1");
var $person1 = $("#newsPerson_1");
var $time1 = $("#newsTime_1");
$.ajax({
url: ‘../json/newsTable.json‘,
type: ‘get‘,
data: " ", //入参
dataType: ‘json‘,
timeout: 6000,
async: false,
success: function(retData) {
//console.log(retData);
$title1.val(retData[0].newsTitle);
$content1.val(retData[0].newsContent);
$person1.text(retData[0].newsPerson);
$time1.text(retData[0].newsTime);
},
error: function(request,testStatus,errorThrown){
//执行错误的方法
if(testStatus == "timeout"){
alert("请求超时!");
}
}
})
});

//先赋值再构建编辑器(异步问题)
$(document).ready(function() {
var $title1 = $("#newsTitle_1");
var $content1 = $("#LAY_demo1");
var $person1 = $("#newsPerson_1");
var $time1 = $("#newsTime_1");
$.ajax({
url: ‘../json/newsTable.json‘,
type: ‘get‘,
data: " ", //入参
dataType: ‘json‘,
timeout: 6000,
async: false,
success: function(retData) {
//console.log(retData);
$title1.val(retData[0].newsTitle);
$content1.val(retData[0].newsContent);
$person1.text(retData[0].newsPerson);
$time1.text(retData[0].newsTime);
},
error: function(request,testStatus,errorThrown){
//执行错误的方法
if(testStatus == "timeout"){
alert("请求超时!");
}
}
})
layui.use([‘layer‘,‘layedit‘,‘laypage‘,‘element‘],function() {
var layer = layui.layer,
layedit = layui.layedit;

//构建一个默认的编辑器
var index = layedit.build(‘LAY_demo1‘);
});
});

layui的编辑器 layedit的异步赋值问题