原創(chuàng)|使用教程|編輯:龔雪|2016-11-18 09:26:17.000|閱讀 1344 次
概述:本教程主要為大家介紹如何使用Kendo UI Web創(chuàng)建自定義組件。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
首先在kendo.ui namespace中擴展基礎(chǔ)的Widget類,還可以創(chuàng)建一些變量來保存值用于向下縮小路徑。
擴展基礎(chǔ)組件:
(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);
添加一個初始化的方法:
現(xiàn)在需要對你的組件提供一個初始化方法,當組件被調(diào)用的時候,這個方法就會被框架調(diào)用,這個初始化函數(shù)需要兩個參數(shù),一個是你正在初始化的組件參數(shù),一個是不久你將要指定的一套選項。這兩個參數(shù)都將會配置值。
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 ... } });
現(xiàn)在并不可以添加這個自定義組件到Kendo UI,到這里只是用于創(chuàng)建你自己的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);
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉(zhuǎn)載自:慧都控件網(wǎng)