原創|使用教程|編輯:龔雪|2013-11-08 10:24:13.000|閱讀 3456 次
概述:Kendo UI Web包含數百個創建HTML5 web app的必備元素,包括UI組件、數據源、驗證、一個MVVM框架、主題、模板等。在Kendo UI Web中如何創建自定義組件呢,在下面的文章中將會詳細的進行說明。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
Kendo UI Web包含數百個創建HTML5 web app的必備元素,包括UI組件、數據源、驗證、一個MVVM框架、主題、模板等。在Kendo UI Web中如何創建自定義組件呢,在下面的文章中將會詳細的進行說明。
基礎步驟:
首先在kendo.ui namespace中擴展基礎的Widget類,還可以創建一些變量來保存值用于向下縮小路徑。
擴展基礎組件:
(function($) { // shorten references to variables. this is better for uglification var kendo = window.kendo, ui = kendo.ui, Widget = ui.Widget var MyWidget = Widget.extend({ // initialization code goes here }); })(jQuery);
添加一個初始化的方法:
現在需要對你的組件提供一個初始化方法,當組件被調用的時候,這個方法就會被框架調用,這個初始化函數需要兩個參數,一個是你正在初始化的組件參數,一個是不久你將要指定的一套選項。這兩個參數都將會配置值。
var MyWidget = Widget.extend({ init: function(element, options) { // base call to initialize widget Widget.fn.init.call(this, element, options); } });
對組件添加選項:
var MyWidget = Widget.extend({ init: function(element, options) { // base call to initialize widget Widget.fn.init.call(this, element, options); }, options: { // the name is what it will appear as off the kendo namespace(i.e. kendo.ui.MyWidget). // The jQuery plugin would be jQuery.fn.kendoMyWidget. name: "MyWidget", // other options go here ... } });
現在并不可以添加這個自定義組件到Kendo UI,到這里只是用于創建你自己的Kendo UI組件并使得它像其他的組件一樣可用的一個完整的樣板。
自定義組件樣板:
(function($) { // shorten references to variables. this is better for uglification var kendo = window.kendo, ui = kendo.ui, Widget = ui.Widget var MyWidget = Widget.extend({ init: function(element, options) { // base call to widget initialization Widget.fn.init.call(this, element, options); }, options: { // the name is what it will appear as off the kendo namespace(i.e. kendo.ui.MyWidget). // The jQuery plugin would be jQuery.fn.kendoMyWidget. name: "MyWidget", // other options go here .... } }); ui.plugin(MyWidget); })(jQuery);
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉載自:慧都控件