在knockout.js中使用mustache模板

Using mustache templates with knockout.js

本文关键字:mustache 模板 knockout js      更新时间:2023-09-26

我希望使用knockout.js,但不幸的是,由于jquery 1.4.2的前提,我不能使用jquery-tmpl,(我不会在这里深入讨论)我们无法升级到。

有没有人对开始使用胡子模板与淘汰赛有任何提示?我发现很难找到任何关于它的信息

Update我已经发布了knockout js模板引擎的初始版本,它使用mustache作为模板库。您可以在https://github.com/WTK/ko.mustache.js

查看。

你看过这部分文档http://knockoutjs.com/documentation/template-binding.html吗?特别是仔细看看注释8,它指出您要检查knockout源代码中的jqueryTmplTemplateEngine.js(为了节省您搜索的精力,它是这个:https://github.com/SteveSanderson/knockout/blob/master/src/templating/jquery.tmpl/jqueryTmplTemplateEngine.js)。

我只是看了一眼那个文件的来源,但是一切似乎都很简单。你必须定义一对回调函数,(我假设)在需要时由knockout js调用。

这些功能包括:

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

检查使用jquery时这些函数返回什么。并尝试模仿他们的行为,而使用胡须代替。