2016-10-02 55 views
-2

我對着在那裏我得到錯誤的underscore.js未捕獲的語法錯誤:之後參數列表

underscore.js:(Line number-1442) Uncaught SyntaxError: missing) after argument list.

我使用jQuery,下劃線和Backbone.js的在我的項目這個奇怪的問題丟失)。當我嘗試在另一個視圖中渲染視圖時,我遇到了上述問題。以下是我的代碼片段。

當我的代碼試圖從我的html文件中獲取模板時,我得到錯誤。即在MailListView的渲染方法的第一行。如果我嵌套視圖,是否需要傳遞更多變量?它可能與版本有關嗎?

HTML代碼------------------------

<!doctype html> 
<html> 
<head> 
    <meta charset="UTF-8"> <!--Character encodinng--> 
    <meta name="viewport" content="width=device-width, initial-scale=1.0"> 
    <title>My App</title> 
    <link href="css/bootstrap.min.css" rel="stylesheet"> 
    <link href="css/css.css" rel="stylesheet"> 
    <link href="css/fontawesome.min.css" rel="stylesheet"> 
</head> 
<body> 
<nav class="navbar navbar-inverse no-margin no-radius"> 
    <div class="container"> 
     <a class="navbar-brand" href="#">New Mail</a> 
     <div class="navbar-collapse collapse"> 
      <ul class="nav navbar-nav"> 
       <li class="active"><a href="#">Home</a></li> 
       <li><a href="#">About Us</a></li> 
       <li><a href="#">Join Us</a></li> 
       <li class="dropdown"><a class="dropdown-toggle" data-toggle="dropdown" href="#">Learn More</a></li> 
       <ul class="dropdown-menu"> 
        <li class="dropdown-header">Yo Yo Header</li> 
        <li><a href="#">Java</a></li> 
        <li><a href="#">C++</a></li> 
        <li class="divider"></li> 
        <li><a href="#">Java Script</a></li> 
        <li><a href="#">CSS</a></li> 
       </ul> 
      </ul> 
     </div> 
     <div class="navbar-right navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse"> 
      <span class="glyphicons glyphicons-option-vertical"></span> 
     </div> 
    </div> 
</nav> 
<div class="container"> 
    <div class="row"> 

    </div> 
</div> 

</body> 
<script type="text/template" id="temp_mailsender"> 
    <div class="col-sm-12 fa-border"> 
     <div class="navbar navbar-inverse no-margin no-radius"> 
      <a class="navbar-brand">New Message</a> 
      <a class="navbar-brand pull-right">&times;</a> 
     </div> 
     <div class="col-sm-12 sendlist border-bottom-1 no-padding"> 
      <div class="col-sm-1">To</div><div class="bucket"></div> 
      <div class="col-sm-10 no-padding currentmail" contenteditable="true" tabindex="1"></div> 
      <div class="col-sm-1 text-right">Cc Bcc</div> 
     </div> 
     <div class="col-sm-12 subject border-bottom-1 no-padding"> 
      <div class="col-sm-1">Subject</div> 
      <div class="col-sm-11 no-padding" contenteditable="true" tabindex="1"></div> 
     </div> 
    </div> 
</script> 
<script type="text/template" id="temp_maillist"> 
    <span>Hi There</span> 
    <%_.each(data,funtion(item){%> 
    <%console.log(item)%> 
     <%=item%> 
    <%})%> 
</script> 
<script src="js/jquery.js"></script> 
<script src="js/underscore.js"></script> 
<script src="js/backbone.js"></script> 
<script src="js/bootstrap.min.js"></script> 
<script src="js/script.js"></script> 

</html> 

--------骨幹 - Javascript成爲--as式 - 的script.js ------

(function(){ 
var EmailSenderView = Backbone.View.extend({ 
    el:'.row', 
    events:{ 
     'keyup .sendlist':'validate' 
    }, 
    initialize : function(options){ 
     this.options = options; 
    }, 
    render : function(){ 
     var temp = _.template($('#temp_mailsender').html()); 
     var html = temp(); // You can pass on data that you want to render on this template 
     this.$el.html(html).trigger('create'); 
     this.renderEmailListView(); 
    }, 
    validate : function(e){ 
     var keyCode = e.which || e.keyCode; 
     if(keyCode == 13){ 
      var currentMail = $('.currentmail'); 
      var styledEmail; 
      if(currentMail.text().indexOf('@') != -1){ 
       console.log("contains @"); 
       styledEmail = "<span class='correct'><span>"+currentMail.text()+"</span><span class='discard'> &times;</span></span>"; 
      }else{ 
       console.log("Doesn't contains @"); 
       styledEmail = "<span class='incorrect'><span>"+currentMail.text()+"</span><span class='discard'> &times;</span></span>"; 
      } 
      currentMail.text(""); 
      this.addToBucket(styledEmail); 
     } 
    }, 
    renderEmailListView :function(){ 
     var emaiIdListView = new EmailListView({model:emailIdList,el:this.$('.bucket')}); 
     emaiIdListView.render(); 
    }, 
    addToBucket : function(mailId){ 
     console.log("in add to bucket"); 
     var email = new EmailId(); 
     email.set('id',mailId); 
     console.log("in add to bucket before add"); 
     emailIdList.add(email); 
     console.log(emailIdList.length); 
    }, 
    remove : function(e){ 
     emailIdList.remove($(e.target).parent()); 
    } 
}); 
    var EmailListView = Backbone.View.extend({ 
     events:{ 
      'click .discard':'remove' 
     }, 
     initialize : function(options){ 
      var self = this; 
      self.options = options; 
      this.model.on('add remove', self.render(), self); 
     }, 
     render : function(){ 
      console.log("----------------Getting issue at Below Line----------------"); 
      var temp = _.template($('#temp_maillist').html()); 
      console.log("------------This Line not printed on console--------------"); 
      var html = temp(this.options.model); 
      self.$el.html(html).trigger('create'); 
     }, 
     remove : function(e){ 
      this.model.remove($(e.currentTarget).parent()); 
     } 
    }); 
    var EmailId = Backbone.Model.extend({}); 
    var EmaiIdCollection = Backbone.Collection.extend({ 
     model: EmailId 
    }); 
    var emailIdList = new EmaiIdCollection(); 
    var emailSenderView = new EmailSenderView(); 
    emailSenderView.render(); 
})(); 
+0

我從來沒有使用underscore.js,但在他們的網站,他們說,它需要的Node.js – blackpen

+1

您在'<%_。每個(數據,funtion(項目){%>'有一個錯字,你想'功能' –

+0

謝謝你,這是問題.. OOps :) – Gautam

回答

0

所以問題是與函數調用,我錯誤地鍵入funtion代替function

<script type="text/template" id="temp_maillist"> 
    <span>Hi There</span> 
    <%_.each(data,funtion(item){%> 
    <%console.log(item)%> 
     <%=item%> 
    <%})%> 
</script> 
+0

不要忘了「接受」這個答案,通過點擊刻度線的左側,使其變爲綠色。這標誌着問題已解決。 – halfer

0

中的腳本放置收身的標籤,這是無效後,就在把它們。這可能是你的腳本無法工作的原因。

+0

不錯,但大多數瀏覽器會爲你解決這個問題,所以它不會失敗。 –

+0

所以問題實際上是我的模板中的錯字(函數調用是錯誤的) Gautam

相關問題