V
V
Vyacheslav Lebedev2015-04-23 20:28:59
Layout
Vyacheslav Lebedev, 2015-04-23 20:28:59

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
}

That access in the jade compiler is simple:
span= name
But this is not enough for me. I have a two level object:
{
  "first": {
    "img": imgPath + "toaster.jpg",
    "name": "Тостер",
    "desc": "Суперский тостер, купив его один раз в жизни, Вы больше никогда не будете задумываться о его замене.",
    "price": 100
  },
  "1": {
    "img": imgPath + "waffle-iron.jpg",
    "name": "Вафельница",
    "desc": "Чудо вафельница, позволит Вам наслаждаться чудесными вафлями, вкус которых, Вы не забудите никогда.",
    "price": 150
  }
}

Here's how to run through it, I do not understand.
Tried:
- for (var item in store)
    span= item.name или span= store.item.name // разными способами

Then I realized that the store variable does not exist, since a pure object is being passed:
store = getStore();
fn = jade.compileFile('../src/test.jade', {});
html = fn(store);

Question : How to run through a complex object in the compiler, or how to drive the object passed to the compiler into a variable in order to use for or each further.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Sevirinov, 2018-04-21
@Chefranov

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

V
Vyacheslav Lebedev, 2015-04-23
@slavikse

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

Thus html = fn(store[item]);.
In jade, span= name.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question