更新时间:2023-10-06 21:32:46
有两种可能性:
1-将模型的图像路径声明为计算属性。如果你不喜欢,你可以在你的ObjectController 中声明它也支持这个模板:
1- Declare the image path as computed property on your model. If you don't like that, you could declare it also in your ObjectController backing this template:
模板:
// until 1.0 RC7
<img {{bindAttr src="newsItem.imagePath"}}></img>
// from 1.0 final (the above one is deprecated)
<img {{bind-attr src=newsItem.imagePath}}></img>
模型:
App.NewsItem = DS.Model.extend({
imageID: DS.attr('string'),
imagePath: function() {
return "/assets/news/"+this.get("imageID")+".jpg";
}.property('imageID')
});
2-如果你不需要绑定1(我猜你的id不会改变)并使用 unbound helper
,这不会导致脚本标签:
2- If you do not need the binding in 1 (i guess your id won't change) and use the unbound helper
, which does not result in script tags:
<img src="news{{unbound newsItem.imageID}}.jpg"></img>