【问题标题】:Jade returning error with Unexpected token {Jade 返回错误,带有 Unexpected token {
【发布时间】:2015-07-13 20:40:14
【问题描述】:

我在第 18-19 行(在本例中为 dayClick 行)不断收到错误消息: 意外的标记 { at 函数(本机) 在 assertExpression (C:\websites\timeoffcalendar\node_modules\jade\lib\lexer.js:30:33) 在 Object.Lexer.conditional (C:\websites\timeoffcalendar\node_modules\jade\lib\lexer.js:509:11) 在 Object.Lexer.next (C:\websites\timeoffcalendar\node_modules\jade\lib\lexer.js:914:15) 在 Object.Lexer.lookahead (C:\websites\timeoffcalendar\node_modules\jade\lib\lexer.js:113:46) 在 Parser.lookahead (C:\websites\timeoffcalendar\node_modules\jade\lib\parser.js:102:23) 在 Parser.peek (C:\websites\timeoffcalendar\node_modules\jade\lib\parser.js:79:17) 在 Parser.block (C:\websites\timeoffcalendar\node_modules\jade\lib\parser.js:704:30) 在 Parser.tag (C:\websites\timeoffcalendar\node_modules\jade\lib\parser.js:817:24) 在 Parser.parseTag (C:\websites\timeoffcalendar\node_modules\jade\lib\parser.js:738:17) 在 Parser.parseExpr (C:\websites\timeoffcalendar\node_modules\jade\lib\parser.js:211:21) 在 Parser.block (C:\websites\timeoffcalendar\node_modules\jade\lib\parser.js:708:25) 在 Parser.tag (C:\websites\timeoffcalendar\node_modules\jade\lib\parser.js:817:24) 在 Parser.parseTag (C:\websites\timeoffcalendar\node_modules\jade\lib\parser.js:738:17) 在 Parser.parseExpr (C:\websites\timeoffcalendar\node_modules\jade\lib\parser.js:211:21) 在 Parser.block (C:\websites\timeoffcalendar\node_modules\jade\lib\parser.js:708:25)

block content
  script.
    $(document).ready(function() {
      // page is now ready, initialize the calendar...
      $('#calendar').fullCalendar({
        eventSources: [
          {url: '/getevents'}, 
          {url: "/javascripts/Holidays.json"},
        ],
        header: {
            left: 'prev,next today',
            center: 'title',
            right: 'month,agendaWeek,agendaDay'
        },
        editable: true,
        dayClick: function(date, jsEvent, view) {
            $('#calendar').fullCalendar('changeView', 'agendaDay');
            $('#calendar').fullCalendar('gotoDate', date);
        },
        eventClick: function(event, jsEvent, view) {
            $('#editModalTitle').html(event.title);
            if(Cookies.get("fullAdmin") != "undefined"){
              var sdate = event.start.format().split("T")[0];
              var stime = event.start.format().split("T")[1];
              var edate = event.end.format().split("T")[0];
              var etime = event.end.format().split("T")[1];
              $("#startday").val(sdate);
              $("#starttime").val(stime);
              $("#endday").val(edate);
              $("#endtime").val(etime);
            } else {
              $('#startDate').html("Start date: "+event.start.format());
              $('#endDate').html(" End Date: "+event.end.format());
            }
            $('#dayoffid').val(event.id);
            $('#fullCalModal').modal();
            return false;
        }
      });
      if(Cookies.get("date") != "undefined"){
        $('#calendar').fullCalendar('gotoDate', Cookies.get("date"));
        Cookies.remove("date");
      }
      $('#allday').change(function() {
        if(document.getElementById('allday').checked == true) {
          $('#starttime').val("09:00:00");
          $('#endtime').val("17:00:00");
        } 
        });
      $('#startday').change(function () {
        $('#endday').val($('#startday').val());
        });
      $('#saveevent').click(function(){
        $.ajax({
          type: "POST",
          url: "/calendar/"+$('#startday').val()+"/"+$('#starttime').val()+"/"+$('#endday').val()+"/"+$('#endtime').val()+"/"+$('#typeoptions').val()+"/"+$('#useroptions').val()      
          }).success(function(msg){
            window.location.reload();
          });
        });
      $('#updateEvent').click(function(){
        $.ajax({
          type: "PUT",
          url: "/calendar/"+$('#startday').val()+"/"+$('#starttime').val()+"/"+$('#endday').val()+"/"+$('#endtime').val()+"/"+$('#typeoptions').val()+"/"+$('#useroptions').val()      
          }).success(function(msg){
            window.location.reload();
          });
        });
      $('#addEvent').click(function(){
          $('#createModalTitle').html("Book a day off!");
          $('#inputCalModal').modal();
          return false;
        });
      $('#removeEvent').click(function() {
        if(confirm("Are you sure you want to delete the event?")) {
          $.ajax({
          type: "DELETE",
            url: "/calendar/"+$('#dayoffid').val()             
            }).success(function(msg){
              window.location.reload();
          });
        }
      });
    }); 

【问题讨论】:

  • 为什么不把整个脚本写在一个单独的文件中,并用script(src=包含它,你应该检查你的缩进

标签: node.js express pug


【解决方案1】:

我不认为你的玉模板有问题,我用这个代码在这个site上试了一下..

doctype html
html(lang="en")
  head
   title= pageTitle
  body
   block content
   script.
    $(document).ready(function() {
    // page is now ready, initialize the calendar...
    //And the rest of your script

    });

它生成了没有错误的有效 html

【讨论】:

    猜你喜欢
    • 2017-06-08
    • 2015-03-26
    • 2014-11-26
    • 2018-11-29
    • 1970-01-01
    • 1970-01-01
    • 2015-04-21
    • 1970-01-01
    • 2023-02-08
    相关资源
    最近更新 更多