layedit 須要先構建編輯器 再輸出數據ajax
若是取值 慢於 構建編輯器 那麼數據在編輯器中就沒法顯示了json
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'); });});