将 Mustache 模板与 Knockout.js 一起使用
我希望使用knockout.js,但不幸的是,由于jquery 1.4.2的先决条件,我无法使用jquery-tmpl,我们无法升级到jquery 1.4.2(我不会在这里讨论它)。
有人对开始使用 Mustache 模板和淘汰赛有任何建议吗?我一直发现很难找到有关它的任何信息。
I wish to use knockout.js, but unfortunately I cannot use jquery-tmpl due to the prequisite of jquery 1.4.2, which (I won't go into it here) we cannot upgrade to.
Has anyone got any tips on getting started using Mustache templates with knockout? I've been finding it tricky to find any information regarding it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
更新我已经发布了knockout js模板引擎的初始版本,它使用mustache作为模板库。您可以在 https://github.com/WTK/ko.mustache.js
您是否看过文档的这一部分http://knockoutjs.com/documentation/template-binding。 html?特别是仔细看看Note 8,它指出你要检查knockout源代码中的jqueryTmplTemplateEngine.js(为了省去你搜索的麻烦,就是这个:https://github.com/SteveSanderson/knockout/blob/master/src/templated/jquery.tmpl/jqueryTmplTemplateEngine.js)。
我只是看了一眼该文件的源代码,但一切似乎都很简单。您必须定义几个回调函数(我假设)在需要时由 knockout js 调用。
这些函数包括:
检查这些函数在使用 jquery.tmpl 时返回的内容,并尝试在使用 Mustache 时模仿它们的行为。
Update I've released initial version of template engine for knockout js that is using mustache as a template library. You can check it out at https://github.com/WTK/ko.mustache.js
Have you seen this part of documentation http://knockoutjs.com/documentation/template-binding.html ? Especially take a closer look at the Note 8 which points you to check the jqueryTmplTemplateEngine.js in the knockout source code (to spare you the effort of searching, its this one: https://github.com/SteveSanderson/knockout/blob/master/src/templating/jquery.tmpl/jqueryTmplTemplateEngine.js).
I just took a glance at source of that file, but everything seems to be quite simple. You have to define couple of callback functions that are (I assume) called by knockout js when needed.
Those functions include:
Check what those functions return when using jquery.tmpl and try to mimic their behavior whilst using moustache instead.