---
title: Scope
project: jComponent V19
version: 19.194
section: reference
language: sk
license: MIT
url: https://totaljs.es/docs/sk/jcomponent-v19/19-194/reference/scope/
updated: 2026-11-18T14:27:30.824Z
---

# Scope

> Vlastnosti a metódy objektu scope.

Objekt scope predstavuje element [`ui-plugin`](../ui-plugin/) na stránke. Path použité cez tento objekt sú relatívne k path scopu. Objekt získaš pomocou `$(element).scope()`. Koncept vysvetľuje časť [Scopy](../../guides/scopes/).

## API

### scope.path

Type: `property`

Absolútna path scopu.

Example: Čítanie path
```js
var scope = $('span').last().scope();
console.log(scope.path);  // users
```

### scope.id

Type: `property`

Jedinečný vygenerovaný identifikátor scopu.

Rovnaká hodnota je dostupná ako `ID`.

Example: Čítanie id
```js
var scope = $('span').last().scope();
console.log(scope.id === scope.ID);  // true
```

### scope.element

Type: `property`

Element scopu ako objekt jQuery.

Example: Čítanie element
```js
var scope = $('span').last().scope();
console.log(scope.element.prop('tagName'));  // UI-PLUGIN
```

### scope.config

Type: `property`

Spracovaná konfigurácia elementu.

Example: Čítanie config
```js
var scope = $('span').last().scope();
console.log(scope.config.limit);  // 10
```

### scope.parent

Type: `property`

Nadradený scope.

Pri scope bez nadradeného scopu je vlastnosť `undefined`.

Example: Čítanie parent
```js
var scope = $('span').last().scope();
console.log(scope.parent.path);  // users
```

### scope.isolated

Type: `property`

Určuje, či path ignoruje nadradený scope.

Example: Čítanie isolated
```js
var scope = $('span').last().scope();
console.log(scope.isolated);  // false
```

### scope.elements

Type: `property`

Elementy nadradených scopov a tohto scopu.

Elementy sú uzly DOM a posledný z nich je element tohto scopu.

Example: Čítanie elements
```js
var scope = $('span').last().scope();
console.log(scope.elements.length);  // 2
```

### scope.plugin

Type: `property`

[Plugin](../plugin/) pripojený k scopu.

Example: Čítanie plugin
```js
var scope = $('span').last().scope();
console.log(scope.plugin.name);  // users
```

### scope.makepath(path)

Type: `method`

Preloží path relatívnu k scopu.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `path` | `String` | yes |  | Path. |

Returns: `String` Preložená path.

`?` je path scopu, `?1` je path nadradeného scopu a `?2` je path o dve úrovne vyššie. Ak daná úroveň neexistuje, použije sa path scopu.

Example: Použitie makepath()
```js
var scope = $('ui-plugin').scope();
console.log(scope.makepath('?.name'));  // users.name
```

### scope.get([path])

Type: `method`

Prečíta path relatívnu k scopu.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `path` | `String` | no |  | Relatívny path. |

Returns: `Object` Hodnota.

Bez argumentu metóda vráti celý model.

Example: Použitie get()
```js
var scope = $('ui-plugin').scope();
console.log(scope.get('page'));  // 1
```

### scope.set(path, value, [timeout], [reset])

Type: `method`

Zapíše hodnotu na path relatívnu k scopu.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `path` | `String` | yes |  | Relatívny path. |
| `value` | `Object` | yes |  | Hodnota. |
| `timeout` | `Number` | no |  | Hodnota `10` alebo vyššia oneskorí zmenu o zadaný počet milisekúnd. Nižšia hodnota je typ zmeny. |
| `reset` | `Boolean` | no |  | `true` po oneskorenej zmene resetuje stav. |

Example: Použitie set()
```js
var scope = $('ui-plugin').scope();
scope.set('page', 2);
console.log(GET('users.page'));  // 2
```

### scope.push(path, value, [timeout], [reset])

Type: `method`

Pridá položku do poľa relatívneho k scopu.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `path` | `String` | yes |  | Relatívny path. |
| `value` | `Object` | yes |  | Položka. |
| `timeout` | `Number` | no |  | Hodnota `10` alebo vyššia oneskorí zmenu o zadaný počet milisekúnd. Nižšia hodnota je typ zmeny. |
| `reset` | `Boolean` | no |  | `true` po oneskorenej zmene resetuje stav. |

Example: Použitie push()
```js
var scope = $('ui-plugin').scope();
scope.push('items', 'A');
console.log(scope.get('items'));  // ["A"]
```

### scope.update([path], [timeout], [reset])

Type: `method`

Upozorní poslucháčov path relatívnej k scopu.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `path` | `String` | no |  | Relatívny path. |
| `timeout` | `Number` | no |  | Hodnota `10` alebo vyššia oneskorí zmenu o zadaný počet milisekúnd. Nižšia hodnota je typ zmeny. |
| `reset` | `Boolean` | no |  | `true` resetuje stav. |

Example: Použitie update()
```js
var scope = $('ui-plugin').scope();
scope.watch('page', (path, value) => console.log(value));  // 5
window.users.page = 5;
scope.update('page');
```

### scope.change([path])

Type: `method`

Označí komponenty na path ako dotknuté a upravené.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `path` | `String` | no |  | Relatívny path. |

Example: Použitie change()
```js
var scope = $('ui-plugin').scope();
scope.change();
console.log(FIND('field').config.touched);  // true
```

### scope.reset([path])

Type: `method`

Vymaže stav komponentov na path.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `path` | `String` | no |  | Relatívny path. |

Vymaže sa stav dotknutia a úpravy. Hodnota sa nezmení.

Example: Použitie reset()
```js
var scope = $('ui-plugin').scope();
var com = FIND('field');
com.modify('Peter');
scope.reset();
console.log(com.config.touched, com.config.modified);  // false false
```

### scope.default([path], [timeout])

Type: `method`

Obnoví predvolenú hodnotu scopu.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `path` | `String` | no |  | Relatívny path. |
| `timeout` | `Number` | no |  | Oneskorenie v milisekundách. |

Predvolená hodnota pochádza z atribútu [`default`](../ui-plugin/#default) elementu. Číslo ako prvý argument je oneskorenie v milisekundách.

Example: Použitie default()
```js
var scope = $('ui-plugin').scope();
scope.set('page', 5);
scope.default();
console.log(scope.get('page'));  // 1
```

### scope.can()

Type: `method`

Určuje, či sa komponenty v scope dajú uložiť.

Returns: `Boolean` Výsledok.

Výsledok je `true`, keď je aspoň jeden komponent dotknutý a žiadny nie je neplatný. Scope bez komponentov vráti `true`.

Example: Použitie can()
```js
var scope = $('ui-plugin').scope();
FIND('field').modify('Peter');
console.log(scope.can());  // true
```

### scope.errors()

Type: `method`

Vráti dotknuté a neplatné komponenty scopu.

Returns: `Array` Komponenty.

Example: Použitie errors()
```js
var scope = $('ui-plugin').scope();
var com = FIND('field');
com.validate = value => !!value;
com.bind('touched');
com.validate2();
console.log(scope.errors().length);  // 1
```

### scope.watch(path, callback, [init])

Type: `method`

Sleduje path relatívnu k scopu.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `path` | `String` | yes |  | Relatívny path. |
| `callback` | `Function` | yes |  | Funkcia, ktorá dostáva zmeny. |
| `init` | `Boolean` | no |  | `true` zavolá callback okamžite. |

Returns: `Scope` Scope.

Callback dostane `path`, `value` a `type` a `this` je scope.

Example: Použitie watch()
```js
var scope = $('ui-plugin').scope();
scope.watch('page', (path, value) => console.log(path, value));  // users.page 2
scope.set('page', 2);
```

### scope.unwatch(path)

Type: `method`

Odstráni sledovače path.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `path` | `String` | yes |  | Relatívny path. |

Returns: `Scope` Scope.

Metóda odstráni všetky sledovače, ktoré má tento scope na danej path.

Example: Použitie unwatch()
```js
var scope = $('ui-plugin').scope();
scope.watch('page', () => console.log('called'));
scope.unwatch('page');
scope.set('page', 2);
console.log('end');  // end
```

### scope.apply()

Type: `method`

Aktivuje scope.

Returns: `Scope` Scope.

Funkcie ako `SET()` potom nahradia `?` za path tohto scopu.

Example: Použitie apply()
```js
var scope = $('ui-plugin').scope();
scope.apply();
SET('?.page', 3);
console.log(GET('users.page'));  // 3
```

### scope.FIND(selector, [many], [callback], [timeout])

Type: `method`

Nájde komponenty vnútri scopu.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `selector` | `String` | yes |  | Selektor komponentu. |
| `many` | `Boolean` | no |  | `true` vráti pole. |
| `callback` | `Function` | no |  | Počká na komponent a dostane ho. |
| `timeout` | `Number` | no |  | Najdlhšie čakanie v milisekundách. |

Returns: `Component|Array` Výsledok.

Argumenty sú rovnaké ako pri rozšírení jQuery `FIND()`.

Example: Použitie FIND()
```js
var scope = $('ui-plugin').scope();
console.log(scope.FIND('field').name);  // field
```

### scope.SETTER(selector, method, [...args])

Type: `method`

Zavolá metódu komponentov vnútri scopu.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `selector` | `String` | yes |  | Selektor komponentu. |
| `method` | `String` | yes |  | Názov metódy. |
| `args` | `Object` | no |  | Argumenty. |

Example: Použitie SETTER()
```js
var scope = $('ui-plugin').scope();
scope.SETTER('field/reconfigure', 'title:Orders');
console.log(FIND('field').config.title);  // Orders
```

### scope.RECONFIGURE(selector, value)

Type: `method`

Zmení konfiguráciu komponentov vnútri scopu.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `selector` | `String` | yes |  | Selektor komponentu. |
| `value` | `String|Object` | yes |  | Konfigurácia. |

Example: Použitie RECONFIGURE()
```js
var scope = $('ui-plugin').scope();
scope.RECONFIGURE('field', 'title:Orders');
console.log(FIND('field').config.title);  // Orders
```

### scope.find(selector)

Type: `method`

Nájde vnorené elementy.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `selector` | `String|Object` | yes |  | Selektor alebo objekt selektorov. |

Returns: `jQuery|Object` Výsledok.

Objekt selektorov vráti objekt výsledkov jQuery s rovnakými kľúčmi.

Example: Použitie find()
```js
var scope = $('ui-plugin').scope();
console.log(scope.find('span').length);  // 1
```

### scope.closest(selector)

Type: `method`

Nájde najbližší zodpovedajúci nadradený element elementu.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `selector` | `String` | yes |  | Selektor. |

Returns: `jQuery` Výsledok.

Example: Použitie closest()
```js
var scope = $('ui-plugin').scope();
console.log(scope.closest('body').length);  // 1
```

### scope.append(value)

Type: `method`

Pridá obsah na koniec elementu.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `value` | `String|Array` | yes |  | Obsah. |

Returns: `jQuery` Element.

Pole sa spojí.

Example: Použitie append()
```js
var scope = $('ui-plugin').scope();
scope.append('<b>A</b>');
console.log(scope.find('b').text());  // A
```

### scope.event(name, [selector], callback)

Type: `method`

Pripojí k elementu udalosť jQuery.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | Názov udalosti. |
| `selector` | `String` | no |  | Delegovaný selektor. |
| `callback` | `Function` | yes |  | Obslužná funkcia. |

Returns: `Scope` Scope.

Argumenty sú rovnaké ako pri metóde jQuery `on()`.

Example: Použitie event()
```js
var scope = $('ui-plugin').scope();
scope.event('click', 'span', () => console.log('clicked'));  // clicked
scope.find('span').click();
```

### scope.attr(name, [value])

Type: `method`

Prečíta alebo zapíše atribút elementu.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | Atribút. |
| `value` | `String` | no |  | Nová hodnota. |

Returns: `String|Scope` Hodnota, alebo scope, keď odovzdáš `value`.

Example: Použitie attr()
```js
var scope = $('ui-plugin').scope();
scope.attr('title', 'Users');
console.log(scope.attr('title'));  // Users
```

### scope.attrd(name, [value])

Type: `method`

Prečíta alebo zapíše atribút `data-` elementu.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | Názov bez prefixu `data-`. |
| `value` | `String` | no |  | Nová hodnota. |

Returns: `String|Scope` Hodnota, alebo scope, keď odovzdáš `value`.

Example: Použitie attrd()
```js
var scope = $('ui-plugin').scope();
scope.attrd('id', '5');
console.log(scope.attr('data-id'));  // 5
```

### scope.attrd2(name)

Type: `method`

Prečíta atribút `data-` z elementu alebo z jeho najbližšieho nadradeného elementu, ktorý ho má.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | Názov bez prefixu `data-`. |

Returns: `String` Hodnota.

Example: Použitie attrd2()
```js
var scope = $('ui-plugin').scope();
console.log(scope.attrd2('area'));  // main
```

### scope.css(name, [value])

Type: `method`

Prečíta alebo zapíše vlastnosť CSS elementu.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | Vlastnosť. |
| `value` | `String` | no |  | Nová hodnota. |

Returns: `String|Scope` Hodnota, alebo scope, keď odovzdáš `value`.

Example: Použitie css()
```js
var scope = $('ui-plugin').scope();
scope.css('display', 'block');
console.log(scope.css('display'));  // block
```

### scope.autofocus([selector])

Type: `method`

Presunie fokus na prvé viditeľné pole v elemente.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `selector` | `String` | no | `input,select,textarea` | Polia. |

Returns: `Scope` Scope.

Na mobilných zariadeniach metóda nerobí nič.

Example: Použitie autofocus()
```js
var scope = $('ui-plugin').scope();
scope.autofocus();
console.log(document.activeElement.tagName);  // INPUT
```

### scope.remove()

Type: `method`

Odstráni scope, jeho element a jeho komponenty.

Example: Použitie remove()
```js
var scope = $('ui-plugin').scope();
scope.remove();
console.log($('ui-plugin').length);  // 0
```
