---
title: ui-bind
project: jComponent V20
version: 20.015
section: reference
language: de
license: MIT
url: https://totaljs.es/docs/de/jcomponent-v20/20-015/reference/ui-bind/
updated: 2026-11-22T18:42:02.302Z
---

# ui-bind

> Die Attribute und Befehle des Elements ui-bind.

Das Element `<ui-bind>` aktualisiert die Seite jedes Mal, wenn sich der Wert an einem Path ändert. Das Attribut `config` enthält eine Liste von Befehlen, die durch `;` getrennt sind. Wie du es verwendest, erklärt die Anleitung [Datenbindung](../../guides/data-binding/).

Ein Befehl hat die Form `name:expression` oder `name selector:expression`, um auf die Elemente zu wirken, die ein Selektor innerhalb des Ziels findet. Ohne Ausdruck verwendet der Befehl den Wert am Path. Der Ausdruck ist JavaScript und kann `value`, `path`, `flags`, `element` und `el` (dasselbe wie `element`) verwenden. Verbinde Befehlsnamen mit `+`, damit sie denselben Ausdruck erhalten, zum Beispiel `text+title:value`. Schreibe `\\;` für ein Semikolon innerhalb eines Ausdrucks. Alle Befehle werden einmal ausgeführt, wenn das Element erstellt wird, und zwar mit dem aktuellen Wert am Path. Ein Fehler in einem Ausdruck wird in die Konsole geschrieben, und die Befehle laufen weiter.

## API

### path="path"

Type: `property`

Der zu beobachtende Path.

Ein `?` wird durch den Path des übergeordneten Plugins ersetzt. Mit einem `!` am Anfang (`!common.user`) werden die Befehle nicht ausgeführt, solange der Wert `null` oder `undefined` ist.

Example: Leere Werte überspringen
```html
<ui-bind path="!common.user" config="text:value.name"></ui-bind>

<script>
SET('common.user', { name: 'Peter' });
console.log($('ui-bind').text());
// logs: Peter
</script>
```

### config="commands"

Type: `property`

Die Befehle, durch `;` getrennt.

Die Werte bleiben Strings, weil sie als JavaScript kompiliert werden.

### element="selector"

Type: `property`

Führt die Befehle auf den Elementen aus, die ein Selektor im gesamten Dokument findet.

Example: Element an anderer Stelle der Seite aktualisieren
```html
<h1 id="title"></h1>
<ui-bind path="common.title" element="#title" config="text"></ui-bind>

<script>
SET('common.title', 'Orders');
console.log($('#title').text());
// logs: Orders
</script>
```

### child="selector"

Type: `property`

Führt die Befehle auf den Elementen aus, die ein Selektor innerhalb des Elements findet.

Der Befehl `value` braucht dieses Attribut oder einen Selektor, um ein Eingabefeld zu erreichen.

Example: Eingabefeld füllen
```html
<ui-bind path="common.email" child="input" config="value"><input /></ui-bind>

<script>
SET('common.email', 'info@example.com');
console.log($('input').val());
// logs: info@example.com
</script>
```

### parent="selector"

Type: `property`

Führt die Befehle auf dem nächsten übergeordneten Element aus, das ein Selektor findet.

Example: Übergeordnetes Element ändern
```html
<div class="row">
    <ui-bind path="common.active" parent=".row" config=".selected"></ui-bind>
</div>

<script>
SET('common.active', true);
console.log($('.row').attr('class'));
// logs: row selected
</script>
```

### plugin="path"

Type: `property`

Erstellt ein Plugin auf dem Element selbst, und ein `?` im Path verweist darauf.

Example: Ein Binder mit eigenem Plugin
```html
<ui-bind plugin="clock" path="?.time" config="text"></ui-bind>

<script>
PLUGIN('clock', function(exports) {
    exports.make = () => exports.set('time', '12:00');
});

console.log($('ui-bind').text());
// logs: 12:00
</script>
```

### .name:expression

Type: `command`

Schaltet die CSS-Klasse `name` je nach Ergebnis des Ausdrucks um.

Example: Klassen umschalten
```html
<ui-bind path="common.count" config=".empty:!value;.many:value > 10"></ui-bind>

<script>
SET('common.count', 20);
console.log($('ui-bind').attr('class'));
// logs: many
</script>
```

### text:expression

Type: `command`

Setzt den Text des Elements. HTML wird maskiert.

Ein Ergebnis `null`, `undefined`, `false` oder ein leerer String schreibt den Wert des Befehls `empty`, und `0` wird als `0` geschrieben. Solange das Element durch `show`, `hide`, `visible` oder `invisible` verborgen ist, wird nichts geschrieben, es sei denn, `forcerender` erlaubt es.

Example: Text anzeigen
```html
<ui-bind path="common.name" config="text:value.toUpperCase()"></ui-bind>

<script>
SET('common.name', 'anna');
console.log($('ui-bind').text());
// logs: ANNA
</script>
```

### html:expression

Type: `command`

Setzt den HTML-Inhalt des Elements.

Es gelten dieselben Regeln wie bei `text`, aber ohne Maskierung.

Example: Markup rendern
```html
<ui-bind path="common.name" config="html:'<b>' + value + '</b>'"></ui-bind>

<script>
SET('common.name', 'Anna');
console.log($('ui-bind').html());
// logs: <b>Anna</b>
</script>
```

### value selector:expression

Type: `command`

Setzt den Wert eines Formularelements.

Verwende einen Selektor oder das Attribut `child`, weil das Element `<ui-bind>` selbst kein Formularelement ist.

Example: Eingabefeld mit einem Selektor füllen
```html
<ui-bind path="common.city" config="value input"><input /></ui-bind>

<script>
SET('common.city', 'Bratislava');
console.log($('input').val());
// logs: Bratislava
</script>
```

### title:expression

Type: `command`

Setzt das Attribut `title`.

Example: Text und Titel zusammen
```html
<ui-bind path="common.name" config="text+title:value"></ui-bind>

<script>
ON('ready', function() {
    SET('common.name', 'Anna');
    console.log($('ui-bind').text(), $('ui-bind').attr('title'));
});
// logs: Anna Anna
</script>
```

### href:expression

Type: `command`

Setzt das Attribut `href`.

### src:expression

Type: `command`

Setzt das Attribut `src`.

Example: Attribute mit Selektoren setzen
```html
<ui-bind path="common.user" config="href a:'/users/' + value.id;title a:value.name;src img:value.photo">
    <a><img /></a>
</ui-bind>

<script>
SET('common.user', { id: 7, name: 'Anna', photo: '/a.png' });
console.log($('ui-bind').html().trim());
// logs: <a href="/users/7" title="Anna"><img src="/a.png"></a>
</script>
```

### attr name [selector]:expression

Type: `command`

Setzt das Attribut `name`.

Example: Benutzerdefiniertes Attribut setzen
```html
<ui-bind path="common.id" config="attr data-id:value"></ui-bind>

<script>
SET('common.id', 5);
console.log($('ui-bind').attr('data-id'));
// logs: 5
</script>
```

### show:expression

Type: `command`

Entfernt die CSS-Klasse `hidden`, wenn das Ergebnis truthy ist, und fügt sie andernfalls hinzu.

Example: Ein- und ausblenden
```html
<ui-bind path="common.items" config="show:value > 0">Items</ui-bind>
<ui-bind path="common.items" config="hide:value > 0">Empty</ui-bind>

<script>
SET('common.items', 3);
console.log($('ui-bind').eq(0).hclass('hidden'), $('ui-bind').eq(1).hclass('hidden'));
// logs: false true
</script>
```

### hide:expression

Type: `command`

Fügt die CSS-Klasse `hidden` hinzu, wenn das Ergebnis truthy ist, und entfernt sie andernfalls.

### visible:expression

Type: `command`

Entfernt die CSS-Klasse `invisible`, wenn das Ergebnis truthy ist, und fügt sie andernfalls hinzu.

### invisible:expression

Type: `command`

Fügt die CSS-Klasse `invisible` hinzu, wenn das Ergebnis truthy ist, und entfernt sie andernfalls.

Example: Platz des Elements beibehalten
```html
<ui-bind path="common.ready" config="invisible:!value">Loaded</ui-bind>

<script>
console.log($('ui-bind').attr('class'));
// logs: invisible
SET('common.ready', true);
console.log($('ui-bind').hclass('invisible'));
// logs: false
</script>
```

### forcerender:expression

Type: `command`

Erlaubt `text`, `html` und `template`, bei einem truthy Ergebnis zu rendern, während das Element verborgen ist.

Example: In ein verborgenes Element rendern
```html
<ui-bind id="a" path="common.name" config="show:false;text"></ui-bind>
<ui-bind id="b" path="common.name" config="show:false;forcerender:true;text"></ui-bind>

<script>
SET('common.name', 'Anna');
console.log($('#a').text() === '', $('#b').text());
// logs: true Anna
</script>
```

### template:[{selector}] [selector --> attribute]

Type: `command`

Rendert ein Tangular-Template mit dem Wert.

Das Template stammt aus einem `<script>`- oder `<template>`-Element innerhalb des Ziels, aus dem HTML des Ziels oder aus dem Element in `{selector}`. Das Modell enthält `value`, `path` und `element`. Der Text `SCR` in einem Template wird durch `script` ersetzt.

Mit `selector --> attribute` werden nur die Elemente aktualisiert, die zum Selektor passen. Vorhandene Elemente mit demselben Attributwert bleiben auf der Seite. Ohne Attribut werden ganze Elemente verglichen. Siehe [Templates mit Tangular](../../guides/tangular/).

Example: Liste rendern
```html
<ui-bind path="common.users" config="template">
    <script type="text/html">
        {{ foreach m in value }}<b>{{ m }}</b>{{ end }}
    </script>
</ui-bind>

<script>
SET('common.users', ['Anna', 'Peter']);
console.log($('ui-bind').html().trim());
// logs: <b>Anna</b><b>Peter</b>
</script>
```

Example: Externes Template verwenden und nur geänderte Zeilen aktualisieren
```html
<script type="text/html" id="row"><div data-id="{{ value }}">{{ value }}</div></script>
<ui-bind path="common.id" config="template:{#row} div --> data-id"></ui-bind>

<script>
SET('common.id', 1);
var first = $('ui-bind div')[0];
SET('common.id', 1);
console.log(first === $('ui-bind div')[0]);
// logs: true
</script>
```

### helpers:path

Type: `command`

Setzt das Objekt mit den Tangular-Helpern für den Befehl `template`.

Example: Eigene Helper
```html
<ui-bind path="common.name" config="template;helpers:FUNC.helpers">
    <template>{{ value | shout }}</template>
</ui-bind>

<script>
FUNC.helpers = {
    shout: value => (value || '').toUpperCase() + '!'
};

SET('common.name', 'anna');
console.log($('ui-bind').html().trim());
// logs: ANNA!
</script>
```

### format:value

Type: `command`

Formatiert einen `Date`-Wert für die Befehle `text`, `html`, `value`, `title`, `href`, `src` und `attr`.

Example: Datum formatieren
```html
<ui-bind path="common.date" config="text;format:dd.MM.yyyy"></ui-bind>

<script>
SET('common.date', new Date(2024, 0, 15));
console.log($('ui-bind').text());
// logs: 15.01.2024
</script>
```

### empty:text

Type: `command`

Setzt den Text, den `text`, `html`, `value`, `title`, `href` und `src` schreiben, wenn das Ergebnis `null`, `undefined`, `false` oder ein leerer String ist.

Ohne Wert wird der Text aus `DEF.empty` verwendet (`---`).

Example: Platzhalter anzeigen
```html
<ui-bind path="common.note" config="text;empty:No note"></ui-bind>

<script>
console.log($('ui-bind').text());
// logs: No note
</script>
```

### class:name

Type: `command`

Schaltet einmalig eine CSS-Klasse am Element `<ui-bind>` um, nachdem die Befehle zum ersten Mal ausgeführt wurden.

Example: Element als gerendert markieren
```html
<ui-bind path="common.name" config="text;class:rendered"></ui-bind>

<script>
console.log($('ui-bind').attr('class'));
// logs: rendered
</script>
```

### exec:path

Type: `command`

Ruft eine Funktion mit dem Wert, dem Path und dem Zielelement auf.

Ein `?` im Wert wird durch den Path des übergeordneten Plugins ersetzt. Die Form `?/method` ruft eine Methode des Plugins auf.

Example: Bei jeder Änderung eine Funktion aufrufen
```html
<ui-bind path="common.total" config="exec:FUNC.total"></ui-bind>

<script>
FUNC.total = function(value, path, element) {
    value && console.log(value, path.toString(), element[0].tagName);
};

SET('common.total', 10);
// logs: 10 common.total UI-BIND
</script>
```

### refresh:path

Type: `command`

Ruft wie `exec` eine Funktion mit dem Wert, dem Path und dem Zielelement auf.

### focus:selector

Type: `command`

Verschiebt den Fokus 500 Millisekunden nach der Änderung auf das erste sichtbare Element, das der Selektor findet.

Auf Mobilgeräten wird der Fokus nicht verschoben.

Example: Eingabefeld fokussieren
```html
<ui-bind path="common.open" config="focus:input"><input id="name" /></ui-bind>

<script>
setTimeout(() => console.log(document.activeElement.id), 700);
// logs: name
</script>
```

### checked:expression

Type: `command`

Setzt den Zustand `checked` der Checkboxen und Radiobuttons innerhalb des Ziels.

Example: Checkbox aktivieren
```html
<ui-bind path="common.agree" config="checked"><input type="checkbox" /></ui-bind>

<script>
SET('common.agree', true);
console.log($('input')[0].checked);
// logs: true
</script>
```

### disabled:expression

Type: `command`

Deaktiviert die Formularelemente und Komponenten innerhalb des Ziels, wenn das Ergebnis truthy ist.

Formularelemente sind `input`, `select`, `textarea` und `button`. Komponenten erhalten den Config-Key `disabled`.

Example: Formular deaktivieren
```html
<ui-bind path="common.locked" config="disabled">
    <input />
    <ui-component name="field"></ui-component>
</ui-bind>

<script>
COMPONENT('field', function(self) {});

SET('common.locked', true);
console.log($('input').prop('disabled'), $('ui-component').hclass('ui-disabled'));
// logs: true true
</script>
```

### enabled:expression

Type: `command`

Aktiviert die Formularelemente und Komponenten innerhalb des Ziels, wenn das Ergebnis truthy ist, und deaktiviert sie andernfalls.

Example: Button aktivieren
```html
<ui-bind path="common.valid" config="enabled"><button>Save</button></ui-bind>

<script>
console.log($('button').prop('disabled'));
// logs: true
SET('common.valid', true);
console.log($('button').prop('disabled'));
// logs: false
</script>
```

### required:expression

Type: `command`

Setzt den Config-Key `required` der Komponenten innerhalb des Ziels.

Example: Feld als Pflichtfeld festlegen
```html
<ui-bind path="common.company" config="required"><ui-component name="field"></ui-component></ui-bind>

<script>
COMPONENT('field', function(self) {});

SET('common.company', true);
console.log($('ui-component').component().config.required);
// logs: true
</script>
```

### assign:path

Type: `command`

Schreibt die Instanz des Binders an einen Path.

Die Instanz hat die Methode `exec(value, path, [flags])`, die die Befehle mit einem bestimmten Wert ausführt.

Example: Befehle per Code ausführen
```html
<ui-bind path="common.name" config="text;assign:common.binder"></ui-bind>

<script>
common.binder.exec('Manual', 'common.name');
console.log($('ui-bind').text());
// logs: Manual
</script>
```

### once

Type: `command`

Führt die Befehle nur ein einziges Mal aus.

Mit dem Präfix `!` im Path werden die Befehle für den ersten nicht leeren Wert ausgeführt. Ohne das Präfix laufen sie mit dem Wert, der beim Erstellen des Elements vorhanden ist.

Example: Ersten Wert rendern
```html
<ui-bind path="!common.name" config="once;text"></ui-bind>

<script>
SET('common.name', 'first');
SET('common.name', 'second');
console.log($('ui-bind').text());
// logs: first
</script>
```

### strict

Type: `command`

Ignoriert Änderungen in verschachtelten Paths.

Example: Nur auf den Path selbst reagieren
```html
<ui-bind path="common.user" config="strict;text:value.name"></ui-bind>

<script>
SET('common.user', { name: 'Anna' });
SET('common.user.name', 'Peter');
console.log($('ui-bind').text());
// logs: Anna
</script>
```

### track:name[,name]

Type: `command`

Beschränkt Änderungen in verschachtelten Paths auf die aufgeführten Eigenschaftsnamen.

Eine Änderung am beobachteten Path selbst oder an einem übergeordneten Path führt die Befehle immer aus.

Example: Eine Eigenschaft verfolgen
```html
<ui-bind path="common.user" config="track:name;text:value.name + ' ' + value.age"></ui-bind>

<script>
SET('common.user.age', 30);
console.log($('ui-bind').text());
// logs: Anna 20
SET('common.user.name', 'Peter');
console.log($('ui-bind').text());
// logs: Peter 30
</script>
```

### changes

Type: `command`

Führt die Befehle nur aus, wenn sich der Wert vom vorherigen unterscheidet.

Example: Identische Werte ignorieren
```html
<ui-bind path="common.total" config="changes;exec:FUNC.log"></ui-bind>

<script>
FUNC.log = value => value && console.log(value);

SET('common.total', 1);
SET('common.total', 1);
SET('common.total', 2);
// logs: 1
// logs: 2
</script>
```

### check:path

Type: `command`

Führt die Befehle nur aus, wenn die Funktion am Path einen truthy Wert zurückgibt.

Die Funktion erhält den Wert, den Path und das Element `<ui-bind>`.

Example: Werte filtern
```html
<ui-bind path="common.age" config="check:FUNC.adult;text"></ui-bind>

<script>
FUNC.adult = value => value >= 18;

SET('common.age', 15);
console.log($('ui-bind').text() === '');
// logs: true
SET('common.age', 20);
console.log($('ui-bind').text());
// logs: 20
</script>
```

### delay:milliseconds

Type: `command`

Wartet die angegebene Zeit und führt die Befehle mit dem letzten Wert aus.

Ohne Wert beträgt die Verzögerung 100 Millisekunden.

Example: Schnelle Änderungen zusammenfassen
```html
<ui-bind path="common.search" config="delay:50;text"></ui-bind>

<script>
SET('common.search', 'a');
SET('common.search', 'ab');
console.log($('ui-bind').text() === '');
// logs: true
setTimeout(() => console.log($('ui-bind').text()), 200);
// logs: ab
</script>
```
