DaumEditor icon indicating copy to clipboard operation
DaumEditor copied to clipboard

글 수정모드시 DB에서 가져온 본문의 값을 에디터에 뿌리지 못하고 있습니다 ㅠㅠ

Open perte opened this issue 11 years ago • 1 comments

function.js 파일에 자바스크립트를 전부 모아뒀구요

폼 로드시 body onload="loadContent()"를 호출합니다.

그 소스는 아래와 같이 해 두었습니다.(첨부파일은 아직 구현하지 못해서 코드를 빼놨습니다.

// 폼 로드시 다음 에디터 영역을 호출하여 시작한다. function loadContent() { // 글 수정모드시 DB에서 읽어온 데이터를 hidden 영역에 저장해놨다. 이 값을 에디터의 content 영역에 붙이기 위해 값을 가져온다. var content = document.frmWrite.content.value;

$(function(){
    $.ajax({
        type:"POST", 
        url: "./editor_template.jsp",
        success: function(data){
            $("#editorTd").html(data);
            setConfig(content); // 에디터 초기화시 글이 수정모드일 경우 본문영역의 내용을 파라미터로 가져간다.
        }, 
        error : function(request, status, error) {
            alert("다음 에디터 로딩 에러");
        }
    }); 
});

}

function setConfig(content) { alert(content); var config = { txHost: '', /* 런타임 시 리소스들을 로딩할 때 필요한 부분으로, 경로가 변경되면 이 부분 수정이 필요. ex) http://xxx.xxx.com / txPath: '', / 런타임 시 리소스들을 로딩할 때 필요한 부분으로, 경로가 변경되면 이 부분 수정이 필요. ex) /xxx/xxx/ / txService: 'sample', / 수정필요없음. / txProject: 'sample', / 수정필요없음. 프로젝트가 여러개일 경우만 수정한다. / initializedId: "", / 대부분의 경우에 빈문자열 / wrapper: "tx_trex_container", / 에디터를 둘러싸고 있는 레이어 이름(에디터 컨테이너) / form: 'frmWrite'+"", / 등록하기 위한 Form 이름 _/ txIconPath: "/daumeditor-7.4.9/images/icon/editor/", /_에디터에 사용되는 이미지 디렉터리, 필요에 따라 수정한다. _/ txDecoPath: "/daumeditor-7.4.9/images/deco/contents/", /_본문에 사용되는 이미지 디렉터리, 서비스에서 사용할 때는 완성된 컨텐츠로 배포되기 위해 절대경로로 수정한다. / canvas: { styles: { color: "#123456", / 기본 글자색 / fontFamily: "굴림", / 기본 글자체 / fontSize: "10pt", / 기본 글자크기 _/ backgroundColor: "#fff", /_기본 배경색 _/ lineHeight: "1.5", /_기본 줄간격 / padding: "8px" / 위지윅 영역의 여백 / }, showGuideArea: false }, events: { preventUnload: false }, sidebar: { attachbox: { show: false, confirmForDeleteAll: true }, attacher: { image: { features:{width:298, height:98} / 사진 첨부파일 창 크기 / } } }, size: { contentWidth: 700 / 지정된 본문영역의 넓이가 있을 경우에 설정 */ } }; EditorJSLoader.ready(function(Editor) { editor = new Editor(config);

        Editor.modify({
            "attachments": function () { /* 저장된 첨부가 있을 경우 배열로 넘김, 위의 부분을 수정하고 아래 부분은 수정없이 사용 */
                var allattachments = [];
                for (var i in attachments) {
                    allattachments = allattachments.concat(attachments[i]);
                }
                return allattachments;
            }(),
            //"content": document.getElementById("content")  //내용 문자열, 주어진 필드(textarea) 엘리먼트 
            "content": content
        });
    });

}

이렇게 해두었는데 alert창에서 보면 DB에서 가져온 본문 값은 뜨는데 막상 에디터에는 내용이

써지지 않습니다. 제가 어디를 수정하면 될까요?

perte avatar Feb 09 '15 05:02 perte

"content": content 이부분에 위에 주석처럼 뒤의 content 를 db에서 가져온 본문값을 가지고있는 엘리먼트의 val 또는 html 또는 text 를 이용해서 넣어주세요(jquery기준)

lcoguss avatar Nov 09 '15 06:11 lcoguss