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

    Interface NodeLogical

    Узел логического оператора. Представляет логический оператор && с условным отображением.

    <div>
    ${context.isAdmin && html`<button>Админ-панель</button>`}
    </div>

    Результат:

    {
    "tag": "div",
    "type": "el",
    "child": [
    {
    "type": "log",
    "data": "/context/isAdmin",
    "child": [
    {
    "tag": "button",
    "type": "el",
    "child": [
    {
    "type": "text",
    "value": "Админ-панель"
    }
    ]
    }
    ]
    }
    ]
    }
    <div>
    ${core.notifications.length > 0 && html`
    <div class="notifications">
    ${core.notifications.map(n => html`<div>${n.message}</div>`)}
    </div>
    `}
    </div>

    Результат:

    {
    "tag": "div",
    "type": "el",
    "child": [
    {
    "type": "log",
    "data": "/core/notifications.length",
    "expr": "${[0]} > 0",
    "child": [
    {
    "tag": "div",
    "type": "el",
    "string": {
    "class": "notifications"
    },
    "child": [
    {
    "type": "map",
    "data": "/core/notifications",
    "child": [
    {
    "tag": "div",
    "type": "el",
    "child": [
    {
    "type": "text",
    "data": "[item]/message"
    }
    ]
    }
    ]
    }
    ]
    }
    ]
    }
    ]
    }
    <div>
    ${core.role === 'admin' && core.permissions.includes('delete') && html`
    <button onclick="deleteItem()">Удалить</button>
    `}
    </div>

    Результат:

    {
    "tag": "div",
    "type": "el",
    "child": [
    {
    "type": "log",
    "data": ["user.role", "user.permissions"],
    "expr": "${[0]} === 'admin' && ${[1]}.includes('delete')",
    "child": [
    {
    "tag": "button",
    "type": "el",
    "string": {
    "onclick": "deleteItem()"
    },
    "child": [
    {
    "type": "text",
    "value": "Удалить"
    }
    ]
    }
    ]
    }
    ]
    }

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

    • type - всегда "log" для логических операторов
    • data - путь(и) к данным для условия
    • expr - выражение с индексами (если условие сложное)
    • child - дочерние узлы, которые отображаются только если условие истинно
    interface NodeLogical {
        type: "log";
        data: string | string[];
        expr?: string;
        child: Node[];
    }
    Index

    Properties

    Properties

    type: "log"

    Тип узла - всегда "log" для логических операторов

    data: string | string[]

    Путь(и) к данным для условия

    data: "/context/isAdmin"
    

    data: ["/context/notifications", "/context/count"]
    
    expr?: string

    Выражение с индексами (если условие сложное)

    expr: "${[0]} === 'admin' && ${[1]}.includes('delete')"
    
    child: Node[]

    Дочерние узлы, которые отображаются только если условие истинно