问题
I have a jade variable declared like this:
BUTTONS = { more_blue: {caption: BUTTONS_CAPTIONS.more, style: BUTTONS_STYLES.blue}, more_red: {caption: BUTTONS_CAPTIONS.more, style: BUTTONS_STYLES.red}, see: {caption: BUTTONS_CAPTIONS.see, style: BUTTON_STYLE_PHOTOS}, see_photos: {caption: BUTTONS_CAPTIONS.see_photos, style: BUTTON_STYLE_PHOTOS}, program : {caption: BUTTONS_CAPTIONS.program, style: BUTTON_STYLE_PROGRAM}, see_program : {caption: BUTTONS_CAPTIONS.see_program, style: BUTTON_STYLE_PROGRAM} }
but I would like it to be more readable like this:
BUTTONS = { more_blue: {caption: BUTTONS_CAPTIONS.more, style: BUTTONS_STYLES.blue}
, more_red: {caption: BUTTONS_CAPTIONS.more, style: BUTTONS_STYLES.red}
, see: {caption: BUTTONS_CAPTIONS.see, style: BUTTON_STYLE_PHOTOS}
, see_photos: {caption: BUTTONS_CAPTIONS.see_photos, style: BUTTON_STYLE_PHOTOS}
, program : {caption: BUTTONS_CAPTIONS.program, style: BUTTON_STYLE_PROGRAM}
, see_program : {caption: BUTTONS_CAPTIONS.see_program, style: BUTTON_STYLE_PROGRAM}
}
but this code doesn't compile even if I add backslashes at the end of each line. Are there any workarounds?
回答1:
Jade now supports multineline variables, as described in the docs:
-
list = ["Uno", "Dos", "Tres",
"Cuatro", "Cinco", "Seis"]
each item in list
li= item
回答2:
Your question surprised me. I have made some tests in Jade:
This worked (as you said):
person = {name: 'Bill', age: 50}
This worked too:
- person = {name: 'Bill', age: 50}
This did not (Jade could not compile it:
- person = {
- name: 'Bill',
- age: 50
- }
This is a good workaround:
- person = {}
- person.name = 'Bill'
- person.age = 50
来源:https://stackoverflow.com/questions/20419312/jade-declare-a-variable-over-multiple-lines