上篇大致讲了对源码的理解,这篇展示一个初步的九宫格控件。直接上源码:

webix.protoUI({
name:"grid",
$init:function(config){
config.rowCount = config.rowCount || 3;
config.colCount = config.colCount || 3; if(!config.rows){
config.rows = [];
} config.rows.push({
view:"toolbar",
cols:[
{id:config.id+"btn_2",view:"button",value:"2*2",align:"left",width:60,click:this._adjust},
{id:config.id+"btn_3",view:"button",value:"3*3",align:"left",width:60,click:this._adjust},
{id:config.id+"btn_4",view:"button",value:"4*4",align:"left",width:60,click:this._adjust},
{id:config.id+"_i",view:"text",width:60,align:"right"},
{view:"label",label:"*",width:20,align:"center"},
{id:config.id+"_j",view:"text",width:60,align:"right"},
{id:config.id+"btn_adjust",view:"button",value:"OK",align:"left",width:60,click:this._adjust},
{},
]
}); Array.prototype.push.apply(config.rows, this._initRowCol(config));
this._settings = config;
},
_initRowCol:function(config){
var rows = [];
for(var i=0;i<config.rowCount;i++){
rows.push({cols:[]});
for(var j=0;j<config.colCount;j++){
var tmp = webix.clone(config.itemTemplate);
tmp.id = config.id+"_row"+i+"_col"+j;
rows[i].cols.push(tmp);
}
}
return rows;
},
_reconstruct:function(){
this._collection = this._collection.slice(0, 1);
var rowsConfig = this._initRowCol(this._settings);
Array.prototype.push.apply(this._collection, rowsConfig);
webix.ui.baselayout.prototype.reconstruct.call(this);
},
_adjust:function(id,e){
var parent = this._parent_cell._parent_cell;
var count = id.substr(id.lastIndexOf("_")+1); if(webix.ui.grid.prototype._isNumber.call(parent, count)){
parent._settings.rowCount = parent._settings.colCount = count;
} else {
var id = parent._settings.id;
var i = $$(id+"_i").getValue();
var j = $$(id+"_j").getValue(); if(!webix.ui.grid.prototype._isNumber.call(parent, i) || !webix.ui.grid.prototype._isNumber.call(parent, j)){
webix.message("Please input number");
return;
} parent._settings.rowCount = i;
parent._settings.colCount = j;
} webix.ui.grid.prototype._reconstruct.call(parent);
},
_isNumber:function(num){
return !isNaN(parseFloat(num)) && isFinite(num);
},
}, webix.ui.layout);

效果见这里,几个n*n的按钮在本地跑是OK的,在webix提供的这个沙盒里会出错,具体没深究。这个控件只是基于layout,动态调整config,再调用baselayout.reconstruct。可以往2方面深入下去:

  1. 功能上:加入添加监控、选中当前项、绑定list等
  2. 实现上:基于view自己处理render和event,这样会对原理了解的更深入,也可以学着自己实现一套简单的前端库。

webix custom component-九宫格的更多相关文章

  1. Quartus14.1中Qsys无法更新custom component的问题

    如果对Qsys中custom component进行了改动,如果直接generate HDL无法使改动应用到实际的编译过程,需要对Qsys进行刷新操作,如下:

  2. Quartus14.1中Qsys创建custom component时编译出错原因

    利用Quartus14.1中Qsys工具新建自定义组件时会产生“part-select direction is opposite from prefix index direction”错误,这是由 ...

  3. webix源码阅读

    最近在用webix,需要一个类似九宫格的监控界面.自带的控件里没有,于是萌生出做一个Custom Component的需求.不过webix关于自定义控件的文档比较少,官方只有一篇<Creatin ...

  4. vue从入门到进阶:组件Component详解(六)

    一.什么是组件? 组件 (Component) 是 Vue.js 最强大的功能之一.组件可以扩展 HTML 元素,封装可重用的代码.在较高层面上,组件是自定义元素,Vue.js 的编译器为它添加特殊功 ...

  5. angularjs component

    Component https://docs.angularjs.org/guide/component component本质上就是directive. This is a shorthand fo ...

  6. [翻译]Writing Custom Report Components 编写自定义报表组件

    摘要:简单介绍了如何编写一个FastReport的组件,并且注册到FastReport中使用.   Writing Custom Report Components 编写自定义报表组件 FastRep ...

  7. Using a custom AxisRenderer object

    Using a custom AxisRenderer object http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d1 ...

  8. Vue教程:组件Component详解(六)

    一.什么是组件? 组件 (Component) 是 Vue.js 最强大的功能之一.组件可以扩展 HTML 元素,封装可重用的代码.在较高层面上,组件是自定义元素,Vue.js 的编译器为它添加特殊功 ...

  9. 谈谈我对前端组件化中“组件”的理解,顺带写个Vue与React的demo

    前言 前端已经过了单兵作战的时代了,现在一个稍微复杂一点的项目都需要几个人协同开发,一个战略级别的APP的话分工会更细,比如携程: 携程app = 机票频道 + 酒店频道 + 旅游频道 + ..... ...

随机推荐

  1. HTML5 Web Storage

    Web Storage是HTML5 API提供一个新的重要的特性: 最新的Web Storage草案中提到,在web客户端可用html5 API,以Key-Value形式来进行数据持久存储: 目前主要 ...

  2. 基于eBox的LTC1446驱动

    LTC1446 是linear出品的双通道12bit轨对轨DAC芯片,采用SPI接口,内部基准电压,满量程输出4.095v,单电源供电(4.5-5v).8Pin封装.            使用时非常 ...

  3. 《zw版·Halcon-delphi系列原创教程》 Halcon分类函数011,ocr,字符识别

    <zw版·Halcon-delphi系列原创教程> Halcon分类函数011,ocr,字符识别 为方便阅读,在不影响说明的前提下,笔者对函数进行了简化: :: 用符号“**”,替换:“p ...

  4. 《zw版·Halcon-delphi系列原创教程》 Halcon分类函数008,matrix,矩阵函数

    ** 3dFromFundamentalMatrix( Rows1, Cols1, Rows2, Cols2, CovRR1, CovRC1, CovCC1, CovRR2, CovRC2, CovC ...

  5. tcp粘包,udp丢包

    TCP是面向流的, 流, 要说明就像河水一样, 只要有水, 就会一直流向低处, 不会间断. TCP为了提高传输效率, 发送数据的时候, 并不是直接发送数据到网路, 而是先暂存到系统缓冲, 超过时间或者 ...

  6. 2015弱校联盟(1) - E. Rectangle

    E. Rectangle Time Limit: 1000ms Memory Limit: 65536KB 64-bit integer IO format: %lld Java class name ...

  7. 如何使用R语言解决可恶的脏数据

    转自:http://shujuren.org/article/45.html 在数据分析过程中最头疼的应该是如何应付脏数据,脏数据的存在将会对后期的建模.挖掘等工作造成严重的错误,所以必须谨慎的处理那 ...

  8. C++ string到底是什么

    C++ string到底是什么? 要回答这个问题,先要了解什么是basic_string.看一下basic_string的声明: template < class charT, //定义字符串中 ...

  9. 微信小程序配置文件

    app.json   配置文件中不能有注释 { "pages": [ // 必填 设置页面路径 "pages/index/index", "pages ...

  10. BW常用事务码Tcode

    声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...