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

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. storyboard

    一,代码动态改写 1,一般程序启动就自动执行 main.storyboard 也可以在AppDelegate改写 - (BOOL)application:(UIApplication *)applic ...

  2. 《zw版·Halcon-delphi系列原创教程》 Halcon分类函数001·3D函数

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

  3. 方法过滤器,分布式缓存 Memcached实现Session解决方案

    控制器-〉方法过滤器-〉controller-> 方法 所以通过建立controller基类的方法进行方法过滤,所有控制器先执行基类的OnActionExecuting 方法. using Sp ...

  4. 纯CSS气泡效果

    http://www.liaoxuefeng.com/article/0013738937970388b6b6e5e5e2f4e21b65b01807c84ddf6000

  5. js typeof

    var message = "some thing"; alert(typeof message); // string alert(typeof 95); // number a ...

  6. HDU Coprime

    Coprime Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total S ...

  7. Hadoop安装指引

    pre.ctl { font-family: "Liberation Mono", monospace } p { margin-bottom: 0.25cm; line-heig ...

  8. 理解GRUB2工作原理及配置选项与方法

    GRUB2是借鉴GRUB改写到更加安全强大到多系统引导程序,现在大部分较新的Linux发行版都是使用GRUB2作为引导程序的.GRUB2采用了模块化设计,使得GRUB2核心更加精炼,使用更加灵活,同时 ...

  9. docker-registry使用笔记

    在国内docker-hub是肯定用不了的,不解释:sweat:. 所以最好还是建一个私有的docker-registry,存储一些常用的images方便随时pull. 相关链接 github:http ...

  10. linux复习

    linux的特点           - 免费的/开源           - 支持多线程/多用户           - 安全性好           - 对内存和文件管理优越       关机命令 ...