나는 http://addyosmani.github.io/backbone-fundamentals을 따라 가려고합니다. 나는 엘 엘 (el)이 어떤 관점에서 일하기로되어있는 지 알지 못한다.
가 여기 내 HTML입니다 :
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Dashboard</title>
</head>
<body>
<h1>Dashboard</h1>
<ol class="foo" id="recent-station">
</ol>
<!-- Templates -->
<script type="text/template" id="station-template">
<li><%= station %></li>
</script>
<!-- Javascript -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.4/underscore-min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/backbone.js/1.0.0/backbone-min.js"></script>
<script src="static/js/script.js"></script>
</body>
</html>
그리고 script.js은 다음과 같습니다
var RecentStation = Backbone.Model.extend({
defaults: {
station: "",
},
initialize: function() {
console.log('initialized: ' + JSON.stringify(this));
this.on('change', function() {
console.log('changed: ' + JSON.stringify(this));
})
}
});
var RecentStationView = Backbone.View.extend({
tagName: 'ol',
id: 'recent-station',
initialize: function() {
this.model.bind('change', _.bind(this.render, this));
},
render: function() {
console.log('render');
this.$el.append('<li>foo</li>');
$('ol#recent-station').append('<li>bar</li>');
return this;
},
});
var recent = new RecentStation();
var recentView = new RecentStationView({model: recent});
recent.set('station', 'My Station');
흥미로운 물건 렌더링 기능에 일어나고있다. "렌더링"이 콘솔에 기록 된 것을 볼 수 있으며 "바"텍스트는 노드에 추가되지만 "foo"텍스트에는 추가되지 않습니다. 나는 이것을 $ el과 $ ('ol # recent-station') 같은 것이지만, 분명히 그렇지 않다고 생각했다. 내가 뭘 놓치고 있니?
아, 맞아. 감사. –