aralejs / templatable Goto Github PK
View Code? Open in Web Editor NEW处理组件的模板渲染,混入到 Widget 中使用。
处理组件的模板渲染,混入到 Widget 中使用。
与 templatable 区别
review 下现有代码
https://github.com/aralejs/templatable/blob/master/src/runtime.js
compile 也可以支持简单的 selector
this.element.html($(this._compile()).find(selector).html());
attr中的template属性,我看到dialog之类的组件,都是可以在组件内部赋值的,但是我写的组件,只能 new XXX({
template:""
});
来制作模板,如果我没有通过参数方式制定模板,内部的attr template 并没有生效,会默认生成一个 空div,很奇怪,我少了哪一步吗?
这个库有两个文件 templatable.js 和 runtime.js。
templatable 保持原来的功能;runtime 是简单版的,只支持 handlebars runtime 并且去除了 renderPartial。
迁移的目的是 templatable 的功能本身就相对独立,迁移出来可以方便修改而不会影响底层 widget 组件。
以后可以考虑增强 model 的功能。
{{表达式}}
返回的是SafeString,但有时候,我希望返回的是html代码,而不是转义之后的文本,可以通过配置实现吗,或者只能使用helper?
{{#if gender == 'male' }}
// dosth...
{{/if}}
如何实现上面操作,必须用helper吗?
widget可以使用指定模板吗,如ejs?
Uncaught TypeError: Cannot read property 'compile' of null
我想问一下,model的内容是通过ajax动态获取和改变的,每次改变的时候我是需要重新new 一下自己扩展的TemplateWidget(继承Widget)再render吗?这样对性能会不会有影响?
目前发现这几个组件 autocomplete/select/intro 中, 由于 template 从 .tpl 改成了 .handlebars, this.get("template") 由原来的 string 变成了 Function, 导致在 parseElementFromTemplate (https://github.com/aralejs/templatable/blob/master/src/templatable.js#L18) 时, 使得 this.templateObject 为 null.
再当这几个组件使用 this.renderPartial('[data-role=content]'); 方法时, 使得 https://github.com/aralejs/templatable/blob/master/src/templatable.js#L80 这里的 if 分支 从 执行 true 分支换成了 false 分支, 导致 render 之后, 会出现两个父 div, 即类似于:
<div class="ui-autocomplete" data-widget-cid="widget-0" style="z-index: 99; display: none;">
<div class="ui-autocomplete">
<ul class="ui-autocomplete-ctn" data-role="items">
<li data-role="item" class="ui-autocomplete-item" data-value="[email protected]">[email protected]</li>
<li data-role="item" class="ui-autocomplete-item" data-value="[email protected]">[email protected]</li>
<li data-role="item" class="ui-autocomplete-item" data-value="[email protected]">[email protected]</li>
</ul>
</div>
</div>
解决方法的话, 是否得让 convertTemplateToObject 中, 当 template 为 Fn 时, 不返回 null, 但如果是字符串对象的话, 那当前 model 为空, 怎么编译生成字符串呢...
另外, 是否得让容器模板 和 内容模板分开?
例子里是这样写的
return new Handlebars.SafeString(out);
可是我使用时不存在SafeString这个函数,而是这样的
return new Handlebars.default.SafeString(out);
请问是例子写错了,还是我引用Handlebars有问题?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.