Javascript TypeError:contactList3在编译中未定义
我通过Javascript(json)将数据传递给闭包模板(soy),但在firebug中得到了about错误Javascript TypeError:contactList3在编译中未定义,javascript,jquery,html,google-closure,Javascript,Jquery,Html,Google Closure,我通过Javascript(json)将数据传递给闭包模板(soy),但在firebug中得到了about错误 // Simple html that starts the whole process <html lang="en"> <head> <title>Gigya Social Demo - getContacs</title> <script type="text/javascript" src="jquery.js
// Simple html that starts the whole process
<html lang="en">
<head>
<title>Gigya Social Demo - getContacs</title>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="jquery.lightbox_me.js"></script>
<!-- add the soy js here-->
<script type="text/javascript" src="emailcontacts.js"></script>
<script type="text/javascript" src="invite_emailcontacts_view.js"></script>
<script type="text/javascript">
function openLightbox() {
var data = [{"provider":"Yahoo","firstName":"myname","lastName":"mysurname","nickname":"mynick","email":"email@hotmail.com","photoURL":"http://l.yimg.com/dh/ap/social/profile/profile_b10.png"}];
var invite = new InviteContactEmailView();
console.log(invite);
invite.open(data);
return this;
}
</script>
<style>
#contactsOverlay {
-moz-border-radius: 6px;
background: #eef2f7;
-webkit-border-radius: 6px;
border: 1px solid #536376;
-webkit-box-shadow: rgba(0,0,0,.6) 0px 2px 12px;
-moz-box-shadow: rgba(0,0,0,.6) 0px 2px 12px;;
padding: 14px 22px;
width: 400px;
position: relative;
display: none;
}
</head>
<body onLoad="openLightbox()">
<div id="contactsOverlay">
</body>
</html>
// soy invoker in file invite_emailcontacts_view.js
function InviteContactEmailView() {
this.template = {};
this.template.element = $('#contactsOverlay');
this.elementSelector = this.template.element;
}
InviteContactEmailView.prototype.open = function(contacts) {
this.elementSelector.lightbox_me({destroyOnClose: true, centered: true, onLoad: testme(this.elementSelector, contacts) });
return this;
};
var testme = function(ele, contacts) {
ele.append(jive.invite.emailcontacts.create(contacts));
$('fieldset div').bind('click', function() {
var checkbox = $(this).find(':checkbox');
checkbox.attr('checked', !checkbox.attr('checked'));
});
}
// soy template (on compile resides in file: emailcontacts.js)
{namespace jive.invite.emailcontacts}
/**
* @param contacts
* @depends path=/var/www/statics/js/invite_emailcontacts_view.js
**/
{template .create}
{foreach $contact in $contacts}
<fieldset>
<div>
<div class="data"></div>
<input type="checkbox" id="checkbox">
</div>
</fieldset>
{/foreach}
{/template}
//启动整个过程的简单html
Gigya社交演示-getContacs
函数openLightbox(){
var data=[{“提供者”:“雅虎”,“名字”:“我的名字”,“姓氏”:“我的名字”,“昵称”:“我的尼克”,“电子邮件”:”email@hotmail.com,“photoURL”:http://l.yimg.com/dh/ap/social/profile/profile_b10.png"}];
var invite=new InviteContactEmailView();
console.log(invite);
邀请.开放(数据);
归还这个;
}
#联络索韦莱{
-moz边界半径:6px;
背景:#eef2f7;
-webkit边界半径:6px;
边框:1px实心#536376;
-网络工具包盒阴影:rgba(0,0,0,6)0px 2px 12px;
-莫兹盒阴影:rgba(0,0,0,6)0px 2px 12px;;
填充:14px 22px;
宽度:400px;
位置:相对位置;
显示:无;
}
//文件invite\u emailcontacts\u view.js中的调用者
函数InviteContactEmailView(){
this.template={};
this.template.element=$(“#contactsOverlay”);
this.element选择器=this.template.element;
}
InviteContactEmailView.prototype.open=功能(联系人){
this.elementSelector.lightbox_me({destroonClose:true,centered:true,onLoad:testme(this.elementSelector,contacts)});
归还这个;
};
var testme=功能(元件、触点){
ele.append(jive.invite.emailcontacts.create(contacts));
$('fieldset div').bind('click',function(){
var checkbox=$(this.find(':checkbox');
checkbox.attr('checked'),!checkbox.attr('checked');
});
}
//大豆模板(编译时驻留在文件:emailcontacts.js中)
{名称空间jive.invite.emailcontacts}
/**
*@param联系人
*@depends path=/var/www/statics/js/invite\u emailcontacts\u view.js
**/
{template.create}
{foreach$contact in$contacts}
{/foreach}
{/template}
非常感谢您的任何帮助
关于编译的模板在哪里?在那里放置断点将告诉您更多信息。我怀疑您在使用键contacts调用模板时没有将哈希传递给模板。基本上,您声明的模板应该获得如下数据集:
{contacts: [....]}
这显然是假设您不是在高级模式下编译的