egjs-persist icon indicating copy to clipboard operation
egjs-persist copied to clipboard

네이버와 같은 여러 판으로 구성된 사이트 내에 persist 활용문의

Open changdongchun opened this issue 4 years ago • 1 comments

네이버와 같은 여러 판으로 구성되어있는 사이트내에서 persist를 응용하여 히스토리 BACK시에 화면 구성을 하려고 할때 HTML각각 판을 저장할 수 있는 방법이 있을까요?

changdongchun avatar Sep 16 '20 06:09 changdongchun

안녕하세요. Persist 데모 페이지 제일 아래쪽을 확인해보시면 해당 예제를 확인해보실 수 있습니다. 판마다 key만 달리하여 지정해주시면 될 것 같습니다.

const persist = new eg.Persist("commentModule");

$(".loadCmtBtn").on("click", function() {
	// Make change to the component. (append comments) 
	$.get("/api/123/nextcomment", function(commentHtml) {
		$(".commentContainer").append(commentHtml);		

		// Save snapshot of the component when there is a change
		var snapshot = $(".commentContainer").html();
		persist.set("commentsHTML", snapshot);
	});
});
	
// Restore state when initiate component
if(!persist.get("") === null) {
	var commentsHTML = persist.get("commentsHTML");
	$(".commentContainer").html(commentsHTML);
}

WoodNeck avatar Sep 16 '20 06:09 WoodNeck