티스토리 뷰

Programming/JavaScript, Sencha

EJS Embedded JavaScript

파란크리스마스 2017. 1. 29. 19:24
728x90

EJS Embedded JavaScript

출처 : EJS - JavaScript Templates
Getting Started with EJS
JSON Text를 JSON Object로 변환하기 :: Outsider's Dev Story

ejs.zip

JSON Data

{"title":"Cleaning Supplies","supplies":["mop","broom","duster"]}

List Template

<h1><%= title %></h1>
<ul>
<% for(var i=0; i<supplies.length; i++) {%>
	<li><%= supplies[i] %></li>
<% } %>
</ul>

DEMO

<html>

<head>
<!-- EJS -->
<!-- <script type="text/javascript" src="resources/js/ejs_production.js"></script> -->
<script type="text/javascript" src="resources/js/ejs.js"></script>
<script type="text/javascript" src="resources/js/view.js"></script>
</head>
<body>

<p id="ejs_list">Some text here</p>

<script type="text/javascript">
new EJS({url: 'template/list.ejs'}).update('ejs_list', 'template/list.json');
</script>

</body>
</html>

실행결과

댓글
300x250
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/12   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31
글 보관함