Twitter的typeahead.js:可以使用角JS作为模板引擎?如果不是我怎么替换” {{}}"对于霍根/胡子JS? [英] Twitter typeahead.js: Possible to use Angular JS as template engine? If not how do I replace "{{}}" for Hogan/Mustache js?

查看:155
本文介绍了Twitter的typeahead.js:可以使用角JS作为模板引擎?如果不是我怎么替换” {{}}"对于霍根/胡子JS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 Twitter的typeahead.js 的工作,我不知道是否有可能修改 hogan.js 使用其他的东西比 {{}}

我看的精缩code 现在,我不知道是什么改变的东西那么简单。做一个查找和替换休息吧。

我主要是要求这一点,因为我使用的角度JS但Twitter的预输入需要一个模板引擎,导致Hogan和棱角分明的 {{}} 发生冲突。一个更好的解决办法是简单修改角JS(我知道这是不是一个模板引擎)和霍根开沟以符合以下标准:

任何模板引擎将与typeahead.js工作,只要它符合下列API:

  //引擎有一个返回编译模板的编译功能
变种compiledTemplate = ENGINE.compile(模板);//编译模板有一个渲染函数返回渲染模板
//渲染函数预期的背景下要传递给它的第一个参数
变种的html = compiledTemplate.render(上下文);


解决方案

如果你想使用Hogan.js与角度,你可以做类似改变分隔符:

  VAR文字=我<%例子%GT;模板。
Hogan.compile(文字,{分隔符:'<%%GT;'});

Hey guys I'm working with twitter's typeahead.js and I was wondering if it was possible to modify hogan.js to use something other than {{}}?

I'm looking at the minified code now and I have no idea what to change for something so simple. Doing a find and replace breaks it.

I'm asking this mainly because I'm using Angular JS but twitter's typeahead requires a templating engine, causing hogan and angular's {{}} to clash. An even better solution would be simply modifying Angular JS (I know it's not a templating engine) and ditching Hogan to fit the following criteria:

Any template engine will work with typeahead.js as long as it adheres to the following API:

// engine has a compile function that returns a compiled template
var compiledTemplate = ENGINE.compile(template);

// compiled template has a render function that returns the rendered template
// render function expects the context to be first argument passed to it
var html = compiledTemplate.render(context);

解决方案

If you want to use Hogan.js with Angular, you can change the delimiters by doing something like:

var text = "my <%example%> template."
Hogan.compile(text, {delimiters: '<% %>'});

这篇关于Twitter的typeahead.js:可以使用角JS作为模板引擎?如果不是我怎么替换&rdquo; {{}}&QUOT;对于霍根/胡子JS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆