我有一个 Backbone 应用程序,我想在其中将“主页”链接显示为图标。我正在使用 HandlebarsJS,所以我真的不知道如何实现这一目标。
我想用这个:
<span class="font-entypo icon-home"></span>
然后在我的 CSS 中我会这样做:
span.font-entypo.icon-home:before{content:'\2302'};
所以我的菜单基本上是这样的:
<a href="home"><span class="font-entypo icon-home"></span></a>
<a href="page1">page1</a>
<a href="page2">page2</a>
<a href="page3">page3</a> ....
现在我使用 HandlebarsJS 的 HTML 是这样的:
<a href="{{href}}">{{text}}</a>
我的主干 View 对于每个菜单项都是相似的:
this.insertView(new ItemView({
model: new Navigation.ItemModel({
href: '#page1',
text: 'page1',
triggers: 'page1',
route: this.route
})
}));
有人有想法吗?提前致谢...
最佳答案
简单的解决方案是在模板中添加一个类
<a href="{{href}}" class="{{class}}">{{text}}</a>
在你的模型上,添加属性 class : 'font-entypo icon-home'
关于javascript - BackboneJS + HandlebarsJS - 如何基于css添加图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21741957/