2012-03-26 84 views
0

我如何可以加載或使用劍道UI電網,Backbone.js的,underscore.js和require.js是否有可能實例化一個劍道UI格?劍道UI電網主幹上,要求,強調和劍道

define([ 
'jquery', 
'underscore', 
'backbone', 
'text!templates/cart/cartlist.html' 
], function($, _, Backbone, CartListTemplate){ 

var mainHomeView = Backbone.View.extend({ 
el: $("#cartContainer"), 
render: function(){ 
    $("#grid").kendoGrid({ 
    columns: ["ItemDescription", "Qty", "Price", { command: "destroy" }], 
    }); 
    this.el.html(CartListTemplate); 
} 
}); 
return new mainHomeView; 
}); 

CartListView.render(); 

但它不工作。它沒有出現。有任何想法嗎?

回答

1

作爲一般的參考,我寫了一篇博客文章使用jQuery插件與骨幹,並註明KendoUI幾次爲我的首選控制套件:

http://lostechies.com/derickbailey/2012/02/20/using-jquery-plugins-and-ui-controls-with-backbone/

具體回答你的問題,你有一個你的渲染方法錯誤。

當您致電$("#grid").kendoGrid(...);時,您告訴jQuery在頁面的DOM中查找#grid元素,但該元素尚未存在,因爲它來自CartListTemplate。您需要使用this.$找到您的視圖的HTML代碼中的#grid,你設置視圖的el.html後。


render: function(){ 
    this.$el.html(CartListTemplate); 
    this.$("#grid").kendoGrid(...); 
} 
+0

驚人的傢伙。謝謝 – jongbanaag 2012-03-27 00:51:58