我想使用 knockout.js,但不幸的是我不能使用 jquery-tmpl,因为 jquery 1.4.2 是我们无法升级到的先决条件(我不会在这里深入讨论)。
有没有人知道如何开始使用带有挖空功能的 Mustache 模板?我发现很难找到有关它的任何信息。
最佳答案
更新 我已经发布了用于使用 mustache 作为模板库的 knockout js 模板引擎的初始版本。您可以在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/templating/jquery.tmpl/jqueryTmplTemplateEngine.js)。
我只是看了一眼那个文件的来源,但一切似乎都很简单。您必须定义几个回调函数,这些回调函数(我假设)在需要时由 knockout js 调用。
这些功能包括:
function renderTemplateSource(templateSource, bindingContext, options) {}
function createJavaScriptEvaluatorBlock(script) {}
function addTemplate(templateName, templateMarkup) {}
检查使用 jquery.tmpl 时这些函数返回的内容,并尝试在使用 mustache 时模仿它们的行为。
关于javascript - 在 knockout.js 中使用 mustache 模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7468764/