在Backbone JST模板中渲染图像

时间:2015-11-04 20:42:37

标签: javascript html backbone.js jst

我的图像存储在我的app / assets / images目录中,并且来自我的JST模板(由我的Backbone视图呈现)我试图弄清楚如何获取图像资源路径。 src ='assets / images / image.png'不起作用。有任何想法吗?

由于

2 个答案:

答案 0 :(得分:0)

你可以试试这个:

var imgPath = 'app/assets/images/',
img = 'image.png',
tpl = _.template('<img src="<%- src %>">');

console.debug(tpl({ src:imgPath+img }));

答案 1 :(得分:0)

您是否使用rails作为后端?然后在你的模板文件中它应该是:

 <div class="row">
                        <div class="col-md-12 ">
                            <div class="row">
                                <div class="row-height">
                                    <div class="col-md-8 col-xs-12 col-height col-top">
                                    <h1>
                                        Guardian Standard
                                    </h1>
                                    <p>
                                        Short description of Guardian plan goes here.  Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean euismod bibendum laoreet. Proin gravida dolor sit amet lacus accumsan et viverra
                                    </p>
                                </div>
                                    <div class="col-md-4 col-height col-middle ">
                                        <span class = "visible-lg">
                                            <h3 class="progress-title">Coverage: </h3><div class="progress progress-width text-center"><div data-percentage="0%" style="width: 100%;" class="progress-bar progress-bar-custom" role="progressbar" aria-valuemin="0" aria-valuemax="100">Best</div>
                                    </div>
                                        <br><br><br>
                                    <h3 class ="progress-title">Premium:</h3> <h3>$$$$</h3>
                                </span>

                                </div>
                                </div>
                            </div>
                        </div>
                    </div>

检索资产的路径以<img src="/assets/image">

开头