Grunt contrib jst和underscore.js无法访问模板变量

时间:2014-03-05 21:33:02

标签: backbone.js underscore.js grunt-contrib-jst underscore.js-templating

我正在使用https://github.com/gruntjs/grunt-contrib-jst - 当我编译模板时,我得到了这个:

this["JST"]["menu"] = function(obj) {
obj || (obj = {});
var __t, __p = '', __e = _.escape, __j = Array.prototype.join;
function print() { __p += __j.call(arguments, '') }
with (obj) {
__p += '<div id="nav-bar">\n  <button class="showMenu" id="showMenu"></button>\n  <img src="' +
((__t = ( window.PATH )) == null ? '' : __t) +
'img/stuff/logo-nav.svg" class="logo-nav">\n  <button class="goToShot">\n   </button>\n</div>\n  <ul class="hamburger menu-top-bar">\n    <li class="menu-key">\n      ';
 if(loggedIn && user.email) { ;
__p += '\n        <button class="hamburger-button" id="goToProfile">\n          <!--<img width="300" class="card-avatar" src="' +
((__t = ( window.PATH )) == null ? '' : __t) +
'img/stuff/avatar.svg">-->\n        <span class="ss-icon hamburger-icon">user</span> Ciao ' +
((__t = ( user.email.split('@')[0] )) == null ? '' : __t) +
'!\n         </button>\n        ';
 }else { ;
__p += '\n        <button class="hamburger-button" id="goToLogin">Partecipa!</button>\n        ';
 } ;
__p += '\n    </li>\n    <li class="menu-key">\n      <button class="hamburger-button"  id="goToHome">\n        <span class="ss-icon hamburger-icon">quote</span>\n        Skisunrise storychannel\n      </button>\n    </li>\n    <li class="menu-key">\n      <button class="hamburger-button"  id="goToMyStory">\n        <span class="ss-icon hamburger-icon">Home</span>\n        My Story\n      </button>\n    </li>\n    <li class="menu-key">\n      <button class="hamburger-button"  id="goToUploadBox">\n        <span class="ss-icon hamburger-icon">inbox</span>\n        Upload Box\n      </button>\n    </li>\n    ';
 if(loggedIn && user.email) { ;
__p += '\n      <li class="menu-key">\n      <button class="hamburger-button"  id="goToAbout">\n        <span class="ss-icon hamburger-icon">info</span>\n        About\n      </button>\n    </li>\n    ';
 } ;
__p += '\n    <li>\n      <br>\n    </li>\n  </ul>\n';

}
return __p
};

在我的骨干视图中我正在这样做:

this.$el.html(_.template(window.JST['menu'](),{ user: a, loggedIn: l }));

但我得到的是:

ReferenceError: loggedIn is not defined


if(loggedIn && user.email) { ;

换句话说无法访问这两个变量。我怎样才能通过这些变量呢? 如果模板中没有动态变量,一切正常。

0 个答案:

没有答案