新建命令的步骤 - scutxieyun/nrenderjs GitHub Wiki
-
在json2jsx.js,增加对命令的解析。 比如,这次加入的命令pageto, animate_el,属于老的命令格式(即采用非json字符串,show_el 23424格式。
- 增加新老命令映射:
var _cmdMap = { "hide_el": ["componentDo", "hide"], "show_el": ["componentDo", "show"], "telto" : ["phoneFunc","telto"], "pageto" : ["pageTo"], "anmiate_el": ["componentDo","animate"], "http":function(_link){ var tid = _articleLinkDetect(_link); if(tid != null){ return '{action:"' + linkToAction(_link,"_self") + '",propagate:true}'; } return null; } }
转换后命令为:{action:"pageTo(23)",propagate:true},{action:"componentDo(animate,58237612)",propagate:true}
对于move,比较麻烦,参数是json,转换程序必须解析json,仿造http的处理,实现如下:
"move_el":function(params){ try{ var pat = /move_el:(.*)/; m = pat.exec(params); if(m == null) return null; params = m[1]; var obj = JSON.parse(params); if(obj != null){ obj = obj[0]; var innerP = []; innerP.push("move"); innerP.push(obj.id); innerP.push(obj.position[0]); innerP.push(obj.position[1]); innerP.push(obj.duration); innerP.push(obj.delay); return "{action:"componentDo(" + innerP.join(",") + ")",propagate:true}"; }else{ return null; } }catch(e){ console.log("decode json failed",params); return null; } }
- 增加新老命令映射:
-
到MeCommandMinix实现命令 pageTo, 简单的处理下参数,交给renderjs.helper.gotoPos。这里有个简单的逻辑兼容书报刊,L1Pos,L2Pos,当L1Pos为-1,表示在当前组跳转。请参见相关代码
move,比较麻烦,在MeComponentMixin加入这个函数的支持。
- 内部增加innerXOffset, innerYOffset,
- 增加函数处理move
- 然后在各控件的render后函数加入相关处理