0

我通过Javascript(json)将数据传递给闭包模板(soy),但在firebug中得到了关于错误。

// 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}

非常感谢任何形式的帮助。

问候

4

1 回答 1

1

编译好的模板在哪里?在那里放一个断点会告诉你更多。我怀疑当您使用关键联系人调用模板时,您没有将哈希传递给模板。基本上,您声明的模板应该得到一个看起来像这样的数据集:

{contacts: [....]}

这显然假设您没有在高级模式下编译。

于 2013-09-01T15:06:38.463 回答