Узел логического оператора. Представляет логический оператор && с условным отображением.
<div> ${context.isAdmin && html`<button>Админ-панель</button>`}</div> Copy
<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": "Админ-панель" } ] } ] } ]} Copy
{ "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> Copy
<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" } ] } ] } ] } ] } ]} Copy
{ "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> Copy
<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": "Удалить" } ] } ] } ]} Copy
{ "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
data
expr
child
Тип узла - всегда "log" для логических операторов
Путь(и) к данным для условия
data: "/context/isAdmin" Copy
data: "/context/isAdmin"
data: ["/context/notifications", "/context/count"] Copy
data: ["/context/notifications", "/context/count"]
Optional
Выражение с индексами (если условие сложное)
expr: "${[0]} === 'admin' && ${[1]}.includes('delete')" Copy
expr: "${[0]} === 'admin' && ${[1]}.includes('delete')"
Дочерние узлы, которые отображаются только если условие истинно
Узел логического оператора. Представляет логический оператор && с условным отображением.
Example: Простое логическое условие
Результат:
Example: Логическое условие с проверкой массива
Результат:
Example: Сложное логическое условие
Результат:
Структура узла:
type
- всегда "log" для логических операторовdata
- путь(и) к данным для условияexpr
- выражение с индексами (если условие сложное)child
- дочерние узлы, которые отображаются только если условие истинно