使用带有knockout.js的mustache模板

时间:2022-12-03 07:39:26

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.

我想用淘汰赛。但不幸的是,由于jquery 1.4.2的prequisite,我不能使用jquery-tmpl(我不会在这里讨论),我们不能升级到。

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.

有谁知道如何开始使用带有knockout的Mustache模板吗?我发现找到任何关于它的信息都很棘手。

1 个解决方案

#1


21  

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

我已经发布了knockout js的模板引擎的初始版本,它使用mustache作为模板库。您可以在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).

你见过文档http://knockoutjs.com/documentation/templat-binding.html的这一部分吗?特别要仔细查看Note 8,它指出您要检查jqueryTmplTemplateEngine。knockout源代码中的js(为了让您不必费力搜索,它是:https://github.com/stevesanderson/knockout/blob/masterb/src/templating/jquerytmpl/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.

我只是浏览了一下这个文件的源代码,但是看起来一切都很简单。您必须定义一对回调函数,在需要时由knockout js调用。

Those functions include:

这些功能包括:

function renderTemplateSource(templateSource, bindingContext, options) {}
function createJavaScriptEvaluatorBlock(script) {}
function addTemplate(templateName, templateMarkup) {}

Check what those functions return when using jquery.tmpl and try to mimic their behavior whilst using moustache instead.

检查使用jquery时返回的函数。试着模仿他们的行为,同时使用小胡子。

#1


21  

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

我已经发布了knockout js的模板引擎的初始版本,它使用mustache作为模板库。您可以在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).

你见过文档http://knockoutjs.com/documentation/templat-binding.html的这一部分吗?特别要仔细查看Note 8,它指出您要检查jqueryTmplTemplateEngine。knockout源代码中的js(为了让您不必费力搜索,它是:https://github.com/stevesanderson/knockout/blob/masterb/src/templating/jquerytmpl/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.

我只是浏览了一下这个文件的源代码,但是看起来一切都很简单。您必须定义一对回调函数,在需要时由knockout js调用。

Those functions include:

这些功能包括:

function renderTemplateSource(templateSource, bindingContext, options) {}
function createJavaScriptEvaluatorBlock(script) {}
function addTemplate(templateName, templateMarkup) {}

Check what those functions return when using jquery.tmpl and try to mimic their behavior whilst using moustache instead.

检查使用jquery时返回的函数。试着模仿他们的行为,同时使用小胡子。