使用hogan.js和typeahead.js在html标签上丢失样式

时间:2013-05-11 23:21:57

标签: css hogan.js typeahead.js

我有以下脚本:

    $('#Entity_Wall').typeahead({
        name: 'walls',
        remote: "http://localhost/getsomestuff?text=%QUERY',
        limit: 10,
        template: '{{value}}<div class="template-wall-front-farthest" 
             style="background:url(\'{{image}}\');</div>',
        engine: Hogan
    });

我有以下样式表:

 .template-wall-front-farthest {
        float: left;
        margin-right: 5px;
        background-position: -132px -2px;
        width: 16px;
        height: 19px;
        background-repeat: no-repeat;
  }

应用我的typahead模板时,我的背景图像未正确定位。它漂浮在左边并且具有正确的尺寸,只是错误的位置。为了让它工作,我必须修改我的模板:

template: '{{value}}<div class="template-wall-front-farthest" 
     style="background:url(\'{{image}}\');background-position: -132px -2px;"></div>'

有没有办法可以利用我的CSS样式,而不是直接将其添加到我的模板中?

1 个答案:

答案 0 :(得分:0)

想出来......刚刚将background替换为background-image,如下所示:

    template: '{{value}}<div class="template-wall-dropdown" 
          style="background-image:url(\'{{image}}\');"></div>'