原創|使用教程|編輯:郝浩|2013-09-06 09:32:35.000|閱讀 622 次
概述:本文將為你展示如何在Backbone.View中綁定Kendo UI組件
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
將 Kendo UI 與 Backbone.View 結合使用并不困難,只要你知道如何初始化控件,其他基本上都比較簡單。如果你想在Backbone.View中響應標準的DOM事件,你只需要用events部署就可以了。但如果你想直接處理來自Kendo UI組件的事件,也就是將 Kendo UI 與 Backbone.View 綁定,那就必須再寫一點代碼。
隨著kendo UI Backbone集成項目 v0.0.6的發布,可以在Backbone.View中聲明一個 kendoUIEvents對象和DOM事件。這樣,Kendo UI組件的初始化就完成了,你只需要調用 kendo.Backbone.ViewEvents.delegate 就可以了。
var View = Backbone.View.extend({ template: "<div id='list'></div>", // declare the Kendo UI widget events // the same way you would declare the // Backbone.View "events" kendoUIEvents: { "change #list": "listChanged" }, listChanged: function(e){ console.log("THE LIST CHANGE EVENT FIRED!!!"); }, render: function(){ // render the view however you want this.$el.html(this.template); // instantiate a Kendo UI widget in the view this.$("#list").kendoListView({ dataSource: { data: [{name: "foo"}, {name: "bar"}] }, template: "#= name #" }); // tell the kendo.Backbone plugin to // delegate the view events for // the widgets in this view kendo.Backbone.ViewEvents.delegate(this); }, remove: function(){ // unbind the kendo ui events kendo.Backbone.ViewEvents.undelegate(this); Backbone.View.prototype.remove.call(this); } });
現在,你的kendo UI的Backbone.View就有了一個回調方法。
除了綁定事件之外,你還需要在視圖實例從DOM中關閉或刪除時解除事件。注意到上面例子中的remove方法的重載沒有?它通過調用kendo.Backbone.ViewEvents對象中的undelegate 方法,所以非常容易實現。
remove: function(){ // unbind the kendo ui events kendo.Backbone.ViewEvents.undelegate(this); Backbone.View.prototype.remove.call(this); }
若想獲取更多資料可參考>>
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉載自:慧都控件