HTML Parser для MetaFor - v2.3.2
    Preparing search index...

    Interface NodeMap

    Узел map операции. Представляет итерацию по массиву данных с дочерними элементами.

    <ul>
    ${core.users.map(user => html`<li>${user}</li>`)}
    </ul>

    Результат:

    {
    "tag": "ul",
    "type": "el",
    "child": [
    {
    "type": "map",
    "data": "/core/users",
    "child": [
    {
    "tag": "li",
    "type": "el",
    "child": [
    {
    "type": "text",
    "data": "[item]/name"
    }
    ]
    }
    ]
    }
    ]
    }
    <div>
    ${core.posts.map(({title, content}) => html`
    <article>
    <h2>${title}</h2>
    <p>${content}</p>
    </article>
    `)}
    </div>

    Результат:

    {
    "tag": "div",
    "type": "el",
    "child": [
    {
    "type": "map",
    "data": "/core/posts",
    "child": [
    {
    "tag": "article",
    "type": "el",
    "child": [
    {
    "tag": "h2",
    "type": "el",
    "child": [
    {
    "type": "text",
    "data": "[item]/title"
    }
    ]
    },
    {
    "tag": "p",
    "type": "el",
    "child": [
    {
    "type": "text",
    "data": "[item]/content"
    }
    ]
    }
    ]
    }
    ]
    }
    ]
    }
    <ul>
    ${core.items.map((item, index) => html`
    <li class=${index % 2 === 0 ? 'even' : 'odd'}>
    ${index + 1}. ${item.name}
    </li>
    `)}
    </ul>

    Результат:

    {
    "tag": "ul",
    "type": "el",
    "child": [
    {
    "type": "map",
    "data": "/core/items",
    "child": [
    {
    "tag": "li",
    "type": "el",
    "string": {
    "class": {
    "data": ["index", "item.name"],
    "expr": "${[0]} % 2 === 0 ? 'even' : 'odd'"
    }
    },
    "child": [
    {
    "type": "text",
    "data": ["index", "item.name"],
    "expr": "${[0] + 1}. ${[1]}"
    }
    ]
    }
    ]
    }
    ]
    }
    <div>
    ${core.categories.map(category => html`
    <section>
    <h1>${category.name}</h1>
    ${category.products.map(product => html`
    <div>${product.name}</div>
    `)}
    </section>
    `)}
    </div>

    Результат:

    {
    "tag": "div",
    "type": "el",
    "child": [
    {
    "type": "map",
    "data": "/core/categories",
    "child": [
    {
    "tag": "section",
    "type": "el",
    "child": [
    {
    "tag": "h1",
    "type": "el",
    "child": [
    {
    "type": "text",
    "data": "[item]/name"
    }
    ]
    },
    {
    "type": "map",
    "data": "[item]/products",
    "child": [
    {
    "tag": "div",
    "type": "el",
    "child": [
    {
    "type": "text",
    "data": "[item]/name"
    }
    ]
    }
    ]
    }
    ]
    }
    ]
    }
    ]
    }

    Структура узла:

    • type - всегда "map" для map операций
    • data - путь к массиву данных для итерации
    • child - дочерние узлы, которые будут повторены для каждого элемента массива
    interface NodeMap {
        type: "map";
        data: string;
        child: Node[];
    }
    Index

    Properties

    Properties

    type: "map"

    Тип узла - всегда "map" для map операций

    type: "map"
    
    data: string

    Путь к массиву данных для итерации

    data: "/context/users"
    
    data: "/core/products"
    
    child: Node[]

    Дочерние узлы, которые будут повторены для каждого элемента массива

    child: [
    {
    tag: "li",
    type: "el",
    child: [
    { type: "text", data: "[item]/name" }
    ]
    }
    ]