이 자습서를 사용하여 밑줄을 사용하여 템플릿을 사용했습니다. http://backbonetutorials.com/what-is-a-view/밑줄을 사용하여 업데이트 요소
나는 div 태그 구조에 p 태그의 일부 텍스트를 추가하려고합니다. 이것은 약간의 값이 입력되어야하는 텍스트 일뿐입니다. 이 텍스트의 변수를 업데이트하기 위해 밑줄을 사용하는 방법이 있습니까? 또는 내가
<div id="popup">
<p>I want to add some text in here <%=variable1%>, Then add another variable text in here <%=variable2%></p>
</div>
UPDATE를 템플릿 HTML을 사용 (_template를) 템플릿으로 텍스트를 만든 다음 추가해야합니다 : 나는이 코드를 사용하여 템플릿 문서를 기반으로하고 시도
.
<html>
<head>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/underscore.js"></script>
<script type="text/javascript" src="js/core.js"></script>
</head>
<body>
<div id="popup">
<div id="template_holder"></div>
</div>
<!-- TEMPLATES FOR CANCEL PAYMENT MODEL -->
<script type="text/template" id="card-success_tmp">
<p>I want to add some text in here <%=variable1%>, Then add another variable text in here <%=variable2%></p>
</script>
</body>
</html>
그런 다음 내 핵심 JS 파일에 내 팝업
var variables = {variable1:'[xxxx]', variable2:'[MM/YY]'};
var template = _.template($("#card-success_tmp").html(), variables);
$('#popup #template_holder').html(template);
을 시작 클릭 이벤트 내부에 아래 코드를하지만 위는 여전히 작동하지 않습니다.
난
var template = _.template($("#card-success_tmp").html());
$('#popup #template_holder').html(template({variable1:'[xxxx]', variable2:'[MM/YY]'}));
그것은 텍스트를 표시하지만, 변수에 전달 된 렌더링되지 않습니다 노력했다.
템플릿을 스크립트 태그가 아닌 문자열로 추가하면 작동합니다. 질문은 스크립트 태그에서 작동하지 않는 이유입니다. 텍스트를 렌더링하지만 전달 된 변수는 렌더링하지 않습니다.
var template = _.template("<p>I want to add some text in here <%=variable1%>, Then add another variable text in here <%=variable2%></p>");
$('#popup #template_holder').html(template({variable1:'[xxxx]', variable2:'[MM/YY]'}));
일반 밑줄이 있거나 백본 (jQuery 포함)이 있습니까? – Bergi
일반 백본에는 백본이 없음 – Chapsterj
하지만 jQuery가 있습니까? – Bergi