Я пытаюсь вставить нормальное выражение JavaScript в файл Jade. Но мое приложение продолжает получать сообщение об ошибке, когда я добавляю переменную isAccepted
в свой код. Это сообщение об ошибке.Невозможно вставить переменную JavaScript в Jade
Your app is crashing. Here's the latest log.
Errors prevented startup:
While building the application: jade-test.jade: Jade syntax error: Expected identifier, number, string, >boolean, or null {{isAccepted ? 'class1' : 'class2... ^ packages/compileJade/plugin/handler.js:44:1: Cannot read property 'head' >of undefined (compiling jade-test.jade) (at fileModeHandler)
Your application has errors. Waiting for file change.
Это мой код:
нефрита test.jade
template(name="layout")
h1 This is layout template
h2 This is h2 paragraph
h3 This is h3 paragraph
+hello
template(name="hello")
h4 This is home template
button Click me
p You have click me #{counter} times.
- var isAccepted = true
button(class=isAccepted ? 'class1' : 'class2') I'm the right choice.
нефрита-test.js
if (Meteor.isClient) {
// counter starts at 0
Session.setDefault('counter', 0);
Template.hello.helpers({
counter: function() {
return Session.get('counter');
}
});
Template.hello.events({
'click button': function() {
// increment the counter when button is clicked
Session.set('counter', Session.get('counter') + 1);
}
});
Router.route('/', function() {
this.render('layout');
});
}
if (Meteor.isServer) {
Meteor.startup(function() {
// code to run on server at startup
});
}
@ saimeunt, я следую за руководство с этой страницы: http://jade-lang.com/reference/attributes/. Который говорит: все нормальные выражения JavaScript тоже работают отлично: '- var authenticated = true body (class = authenticated? 'Authed': 'anon')' – Nguyenducthanh
Я думаю, что «meteor-jade» - это всего лишь подмножество всего синтаксиса Jade и вы не можете использовать эту функцию в любом случае. – saimeunt
Большое спасибо. Я буду использовать другой синтаксис. – Nguyenducthanh