Backbone.js代碼示例中的this
屬性函數是如何工作的?這個代碼中的「this」函數是如何起作用的骨幹樣本?
由於代碼中未指定use strict
指令,並且沒有對象傳遞給任何函數,Backbone.js代碼是否默認爲全局應用程序對象,或者它是否執行其他操作?
我假設this.render()
可能呈現給通過下劃線模板傳入的el
屬性指定的DOM元素,但this.$el.html
?
<script type="text/template" id="search_template">
<label>Search</label>
<input type="text" id="search_input" />
<input type="button" id="search_button" value="Search" />
</script>
<div id="search_container"> </div>
<script type="text/javascript">
var SearchView = Backbone.View.extend({
initialize: function({
this.render();
},
render: function(){
// Compile the template using underscore
var template = _.template($("#search_template").html(), {});
// Load the compiled HTML into the Backbone "el"
this.$el.html(template);
}
});
var search_view = new SearchView({ el: $("#search_container") });
</script>
永遠記得縮進和評論你的代碼...也不要忘了今晚刷牙。不要任何額外的牙科賬單。 –
我試圖但我的手機拒絕合作。你爲什麼要付牙醫賬單? –