我正在尝试将现有的Underscore JS库版本升级到我项目的最新版本。
Underscore.js - 1.4.4至1.9.1
现有的图书馆版本 -
jquery - 2.2.4
jQuery Validation Plugin - 1.11.0
jQuery文件下载插件 - 1.4.2
需要js - 2.1.5
但是,在Underscore版本更新后,我在页面加载时看到此问题(在Chrome控制台中)。
这是错误
jquery.js:3818 jQuery.Deerred exception: valueLabel is not defined ReferenceError: valueLabel is not defined
at HTMLElement.eval (eval at h.template (https://xx.xxxx.com/js/lib/underscore.js?v=VERSION:5:16765), <anonymous>:6:20)
at HTMLElement.u (https://xx.xxxx.com/js/lib/underscore.js?v=VERSION:5:16858)
at access (https://xx.xxxx.com/js/lib/jquery.js:3956:12)
at jQuery.fn.init.html (https://xx.xxxx.com/js/lib/jquery.js:5959:10)
at renderPageFooter (https://xx.xxxx.com/js/view/app.js?v=VERSION:44:36)
at r._renderPageContent (https://xx.xxxx.com/js/view/app.js?v=VERSION:17:14)
at N (https://xx.xxxx.com/js/lib/underscore.js?v=VERSION:5:7894)
at Object.<anonymous> (https://xx.xxxx.com/js/lib/underscore.js?v=VERSION:5:8096)
at Object.<anonymous> (https://xx.xxxx.com/js/lib/underscore.js?v=VERSION:5:1247)
at mightThrow (https://xx.xxxx.com/js/lib/jquery.js:3534:29) undefined
VM6910:6 Uncaught ReferenceError: siteName is not defined
at HTMLElement.eval (eval at h.template (underscore.js?v=VERSION:5), <anonymous>:6:8)
at HTMLElement.u (underscore.js?v=VERSION:5)
at access (jquery.js:3956)
at jQuery.fn.init.html (jquery.js:5959)
at render (page.header.js?v=VERSION:26)
at app.js?v=VERSION:15
at Object.execCb (require.js:1696)
at Module.check (require.js:883)
at Module.<anonymous> (require.js:1139)
at require.js:134
app.js中的renderPageFooter代码 -
define([
'underscore',
'backbone',
'vm',
'jquery.soha'
], function (_, Backbone, libVm, libApp) {
"use strict";
var _renderPageContent = function (inputOpt) {
var thisRef = this;
require(['view/page.header'], function (headerOfPage) {
var ViewOfHeader = libVm.create(thisRef, 'headerOfPageViewer', headerOfPage);
ViewOfHeader.render(inputOpt);
});
this.renderPageFooter(inputOpt);
// Some code here
};
var viewOfApplication = Backbone.View.extend({
// Some code here
renderPageFooter: function(inputOpt) {
var modelOfFooter = null;
modelOfFooter = libVm.getAppConfig().getFooter(inputOpt);
if (!libVm.isFed()){
// During Chrome debug, the pointer doesn't reach this 'if' block.
modelOfFooter.valueLabel[0].href = modelOfFooter.valueLabel[0].href.replace(/\?variableAgent=\D\D/,"");
modelOfFooter.valueLabel[0].href = modelOfFooter.valueLabel[0].href + "?variableAgent=" +libVm.currentvariableAgent;
}
var tmplt = libVm.getTemplate('tmpl-footerOfPage', modelOfFooter);
$('footer#footerOfPage').html(tmplt);
},
});
});
从上面的日志 -
at renderPageFooter (https://xx.xxxx.com/js/view/app.js?v=VERSION:44:36)
在App.js中,这指向
行$('footer#footerOfPage').html(tmplt);
我对Javascript很新,可能错过了此问题所需的更多相关信息。如果被问到可以提供更多。
有人可以帮我找到正确的方向来找到解决此类错误的方法以及解决此问题的任何可能解决方案吗?
答案 0 :(得分:-1)
查看_.template()函数的文档 - http://underscorejs.org/#template for 1.9.1 version。
模板实用程序函数将模板字符串作为第一个参数,并返回一个可用于传递模板数据的函数:
// `testTemplate` here is a function!
var testTemplate = _.template("<p><%= name %></p>");
// Now let's pass in the data for the template.
testTemplate({name: 'Joe Doe'});
// it returns: "<p>Joe Doe</p>"