xtemplate¶
富逻辑的 KISSY 模板引擎
KISSY.use('xtemplate',function(S,XTemplate){
// use XTemplate
});
Static Methods¶
Class Detail¶
- class xtemplate.XTemplate¶
- XTemplate (tpl,config)
Parameters: - tpl ({String|Function}) – 字符串模板或编译过的模板函数.
- config (Object) – 配置项.
Configs Detail¶
- XTemplate.config.subTpls¶
{Object} - 局部自定义子模板的键值对,例如
{ 'sub1':'{{title}}', 'sub2':function( scopes ){ return scopes[0].title2; } }
- XTemplate.config.commands¶
{Object} - 局部自定义命令的键值对,例如
{ 'cmd1':function( scopes,option ){ return scopes[0].title2+option.params[0]; } }
- XTemplate.config.name¶
{Object} - 模版名称,可在 chrome dev tools 中看到以该值为名称的模板文件代码
- XTemplate.config.cache¶
{Boolean} - 是否缓存生成的模板函数,默认 true.
Methods Detail¶
- XTemplate.prototype.removeSubTpl()¶
- removeSubTpl (subTplName)删除指定的局部子模板
Parameters: subTplName (String) – 子模板名称
- XTemplate.prototype.addSubTpl()¶
- addSubTpl (subTplName, def)添加指定的局部子模板, 格式类似 subTpls
Parameters: - subTplName (String) – 子模板名称
- def (String|Function) – 添加子模板定义
- XTemplate.prototype.removeCommand()¶
- removeCommand (commandName)删除指定的局部命令
Parameters: commandName (String) – 命令名称
- XTemplate.prototype.addCommand()¶
- addCommand (commandName,fn)添加局部命令, 格式类似 commands
Parameters: - commandName (String) – 命令名称
- fn (Function) – 命令定义
- XTemplate.prototype.compile()¶
- compile ()编译模板
Parameters: subTplName (String) – 子模板名称 Returns: {Function} - 编译过的模板函数
- XTemplate.prototype.render()¶
- render ( data )渲染数据到模板
Parameters: data (Object) – 数据对象 Returns: {String} - 数据融合模版后的字符串
Static Methods Detail¶
- XTemplate.addSubTpl()¶
- addSubTpl( subTplName, def )添加全局子模板, 格式同 addSubTpl()
- XTemplate.addCommand()¶
- addCommand( commandName, fn )添加全局命令, 格式同 addCommand()