2012-07-09 6 views
0

을 템플릿에 값을 추가, 나는 또한 템플릿이 있습니다백본 underscorejs 내가 Backbonejs의 간단한 추가 이벤트가

initialize: function() 
{ 
    this.template = _.template($("#person-template").html()); 
} 

renderperson: function(model) 
{ 
    //model.name is "Jack" for example 
    //Now I want to render this template with Name replaced with "Jack"? 
    $("#somelement").append(); //What to do here??? 
} 

템플릿은 간단하다 :

<script type="text/template" id="person-template"> 
    <div class="person"><%= Name %></div> 
</script> 

답변

2
$("#somelement").append(this.template(this.model.toJSON())); 

당신도 추가해야 할 수 있습니다

_.bindAll(this) 

to initialize method

+0

'this.template'당신이 초기화 함수에 _.bindAll (이)를 추가 않은 기능 – user50992

+0

가 아니다? –

+0

오 렌더링 사용자의 기능을 초기화하기 위해 추가하지 않았습니다. 이제 작동합니다. 죄송합니다. 감사합니다. :) – user50992

0

이 당신을 도울 수있을 수 있습니다 : http://backbonejs.org/#View-render

var Bookmark = Backbone.View.extend({ 
    render: function() { 
    $(this.el).html(this.template(this.model.toJSON())); 
    return this; 
    } 
}); 
관련 문제