ForgeKomponenty
sk

Komponenty

j-Detail

jComponent 20 · jcomponent@20 component Príklad načítaný s jComponent 20

Tento komponent dokáže vykresliť hodnoty z modelu. Podporuje inline mapovanie - pozrite sa do zdrojového kódu príkladu.


Konfigurácia:

  • dateformat {String} formát dátumu (predvolené: DEF.dateformat)
  • datetimeformat {String} formát dátumu a času (predvolené: DEF.dateformat + ' ' + DEF.timeformat)
  • numberformat {Number} predvolený formát čísla (predvolený: prázdny)
  • small {Boolean} umožňuje menší dizajn (predvolené: false)
  • Štýl komponentu style {Number} (predvolené: 1), podporuje štýl 2, 3 (minimálny) a 4 (moderný)
  • defaultgroup {String} predvolený názov skupiny (predvolené: Default)
  • notnull {Boolean} preskočí hodnoty s nulovou hodnotou (predvolené: false)
  • track {String} môže obsahovať cesty rozdelené čiarkou, táto vlastnosť bude sledovať iba zmeny v ťahaných kľúčoch

Prehlásenie o údajoch:

var model = { firstname: 'Peter', lastname: 'Širka', age: 33 };
var items = [{ id: 2, name: 'Banská Bystrica' }, { id: 3, name: 'Bratislava' }];
var form = [];

// The below values will be binded automatically from the "model" (according to the "path" field) because they contain "path" field
form.push({ group: 'Personal', label: 'First name', path: 'firstname', type: 'string', value: model, note: 'This is first name' });
form.push({ group: 'Personal', label: 'Last name', path: 'lastname', type: 'string', value: model, placeholder: 'String' });
form.push({ group: 'Personal', label: 'Age', path: 'age', type: 'number', value: model });

// The below values will be binded from "value" key
form.push({ group: 'Personal', label: 'Birth date', type: 'date', value: NOW });
form.push({ group: 'Additional', label: 'Newsletter', type: 'bool', value: true });
form.push({ group: 'Additional', label: 'City', type: 'list', value: 2, items: 'items' });
form.push({ group: 'Additional', label: 'Color', type: 'color', value: '#e73323' });
form.push({ group: 'Additional', label: 'Icon', type: 'fontawesome', value: 'fas fa-home' });

Vlastnosti údajov v deklarácii údajov:

  • group {String} názov skupiny (povinné)
  • label {String} štítok (povinný)
  • type {String} typ (povinné)
  • note {String} malá poznámka pod hodnotou
  • format {String} číslo napr. 2 alebo formát dátumu dd.MM.yyyy
  • detail {String} URL adresa na získanie údajov pre typ list, príklad: /users/{0}/ a {0} bude nahradená hodnotou zo zoznamu
  • Položky items {Object Array/String} len pre typ list, reťazec môže obsahovať cestu k Array alebo URL address na vyhľadávanie
  • value {Object} hodnota alebo model s hodnotami (potom sa vyžaduje path)
  • path {String} cesta k hodnote v modeli (value musí obsahovať model)
  • template {String} Šablóna Tangular (funguje iba so type:'template' a {{ value }} obsahuje surovú hodnotu a {{ item }} obsahuje celú položku)
  • empty {String} Prázdna hodnota, keď hodnota môže byť nulová (predvolené: ---)
  • show {String} podmienená funkcia value.type === 'company' potom zobrazí, ak je vyhodnotená podmienka true
  • NEW autoformat {Boolean} umožňuje automatické formátovanie pre email alebo phones a iba pre typ string (predvolené: false)
  • NEW colorize {Boolean} zafarbí hodnotu okrem typu list, color a icon
  • NEW plus {String} pridá hodnotu na koniec vykreslenej hodnoty pre typy number a string

Povolené typy v údajoch:

  • string
  • bool
  • number
  • date
  • datetime
  • list
  • color
  • emoji
  • fontawesome
  • password
  • template

Je dobré vedieť:

  • ak skupina obsahuje iba jeden znak, názov skupiny sa nevykreslí

Použite ho so <ui-component name="detail">. Keď komponent ešte nie je načítaný, jComponent ho stiahne pri prvom použití z adresy v DEF.fallback (predvolene CDN Componentator). Autor: Peter Širka. Zdroj: úložisko komponentov Componentator, licencia MIT.

example.html
<div style="width:500px">
	<ui-component name="detail" path="form"></ui-component>
	<br />
	<div>-- OR --</div>
	<br />
	<ui-component name="detail" path="model" config="style:2">
		<script type="text/plain">
			[
				{ name: 'First name', path: 'firstname', type: 'string' },
				{ name: 'Last name', path: 'lastname', type: 'string' },
				{ name: 'Age', path: 'age', type: 'number' }
			]
		</script>
	</ui-component>
	<br />
	<div>-- OR FILTERED --</div>
	<br />
	<ui-component name="detail" path="model" config="style:3">
		<script type="text/plain">
			[
				// Will be displayed, look to show condition ("value" means "model")
				{ name: 'First name', path: 'firstname', type: 'string', show: 'value.type==1' },
				{ name: 'Last name', path: 'lastname', type: 'string', show: 'value.type==1' },
				// Won't be displayed, look to show condition ("value" means "model")
				{ name: 'Age', path: 'age', type: 'number', show: 'value.type==2' }
			]
		</script>
	</ui-component>
	<br />
	<ui-component name="detail" path="model" config="style:4">
		<script type="text/plain">
			[
				// Will be displayed, look to show condition ("value" means "model")
				{ name: 'First name', path: 'firstname', type: 'string', show: 'value.type==1' },
				{ name: 'Last name', path: 'lastname', type: 'string', show: 'value.type==1' },
				// Won't be displayed, look to show condition ("value" means "model")
				{ name: 'Age', path: 'age', type: 'number', show: 'value.type==2' }
			]
		</script>
	</ui-component>
</div>

<script>
	var model = { firstname: 'Peter', lastname: 'Širka', age: 33, type: 1 };
	var items = [{ id: 2, name: 'Banská Bystrica' }, { id: 3, name: 'Bratislava' }];
	var form = [];

	// The below values will be binded automatically from the "model" (according to the "path" field) because they contain "path" field
	form.push({ group: 'Personal', label: 'First name', path: 'firstname', type: 'string', value: model, note: 'This is first name' });
	form.push({ group: 'Personal', label: 'Last name', path: 'lastname', type: 'string', value: model, placeholder: 'String' });
	form.push({ group: 'Personal', label: 'Age', path: 'age', type: 'number', value: model });

	// The below values will be binded from "value" key
	form.push({ group: 'Personal', label: 'Birth date', type: 'date', value: NOW });
	form.push({ group: 'Additional', label: 'Newsletter', type: 'bool', value: true });
	form.push({ group: 'Additional', label: 'City', type: 'list', value: 2, items: 'items' });
	form.push({ group: 'Additional', label: 'Color', type: 'color', value: '#e73323' });
	form.push({ group: 'Additional', label: 'Icon', type: 'fontawesome', value: 'ti ti-home' });
</script>