Answer the question
In order to leave comments, you need to log in
How to iterate over the passed object when compiling jade?
Good evening!
I can't figure out how to iterate over the object passed to jade.
If we take a simple object:
{
"img": imgPath + "toaster.jpg",
"name": "Тостер",
"desc": "Суперский тостер, купив его один раз в жизни, Вы больше никогда не будете задумываться о его замене.",
"price": 100
}
span= name
{
"first": {
"img": imgPath + "toaster.jpg",
"name": "Тостер",
"desc": "Суперский тостер, купив его один раз в жизни, Вы больше никогда не будете задумываться о его замене.",
"price": 100
},
"1": {
"img": imgPath + "waffle-iron.jpg",
"name": "Вафельница",
"desc": "Чудо вафельница, позволит Вам наслаждаться чудесными вафлями, вкус которых, Вы не забудите никогда.",
"price": 150
}
}
- for (var item in store)
span= item.name или span= store.item.name // разными способами
store = getStore();
fn = jade.compileFile('../src/test.jade', {});
html = fn(store);
Answer the question
In order to leave comments, you need to log in
The ::before and ::after pseudo-elements will help with this. We
wrap the image in a div (for example, with the .image-box class),
assign position: relative to the wrapper
and add a pseudo-element (for example, .image-box::before)
assign position: absolute to the pseudo-element
Further itself. ..
about pseudo-elements...
frame example
ANSWER :
In node, we run through the object (for in), and return the primitives from the complex object:
for (var item in store) {
html = fn(store[item]);
}
"img": imgPath + "waffle-iron.jpg",
"name": "Вафельница",
"desc": "Чудо вафельница, позволит Вам наслаждаться чудесными вафлями, вкус которых, Вы не забудите никогда.",
"price": 150
html = fn(store[item]);
. span= name
.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question