Skip to content

Instantly share code, notes, and snippets.

@ageldama
Created November 30, 2012 02:44
Show Gist options
  • Select an option

  • Save ageldama/4173461 to your computer and use it in GitHub Desktop.

Select an option

Save ageldama/4173461 to your computer and use it in GitHub Desktop.
EJS element 방식으로 HTML에 내장하여 사용하기.
<!-- 사용할 자바스크립트 참조 -->
<script type='text/javascript' src='underscore.js 참조'></script>
<script type='text/javascript' src='jquery.js 참조'></script>
<script type='text/javascript' src='ejs.js 참조'></script><!-- http://embeddedjs.com/ -->
<!-- EJS 템플릿 예제. -->
<!--
* type='text/template' 으로 지정.
* 이후에 참조를 위해서 id 속성을 지정.
* 내용중 EJS 코드은 [% ... %]이나 [%= ... %]으로 삽입.
-->
<script type='text/template' id='myEjsTmpl'>
<select>
<option value="">옵션을 선택하여 주시기 바랍니다</option>
[% _.each(options, function(row){ %]
<option value="[%=row.OPT_CODE%]" >[%=row.OPT_CODE_NM%]</option>
[% }); %]
</select>
</li>
</script>
<script type='text/javascript'>
// 미리 지정한 템플릿의 id을 element으로 참조하여 EJS 템플릿 확장하여 html얻기.
var html = new EJS({element: 'myEjsTmpl'}).render([
{OPT_CODE_: '123', OPT_CODE_NM: 'test1'},
{OPT_CODE_: '456', OPT_CODE_NM: 'test2'}
]);
// html 얻은걸 화면에 추가.
$('#some_div').append(html);
</script>
<div id='some_div'></div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment