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

# Scope

> Le proprietà e i metodi di un oggetto scope.

Un oggetto scope rappresenta un elemento [`ui-plugin`](../ui-plugin/) nella pagina. I path usati tramite l'oggetto sono relativi al path dello scope. Ottieni l'oggetto con `$(element).scope()`. [Scope](../../guides/scopes/) spiega il concetto.

## API

### scope.path

Type: `property`

Il path assoluto dello scope.

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

### scope.id

Type: `property`

L'identificatore univoco generato dello scope.

Lo stesso valore è disponibile come `ID`.

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

### scope.element

Type: `property`

L'elemento dello scope come oggetto jQuery.

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

### scope.config

Type: `property`

La configurazione analizzata dell'elemento.

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

### scope.parent

Type: `property`

Lo scope padre.

La proprietà è `undefined` per uno scope senza padre.

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

### scope.isolated

Type: `property`

Indica se il path ignora lo scope padre.

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

### scope.elements

Type: `property`

Gli elementi degli scope padre e di questo scope.

Gli elementi sono nodi DOM e l'ultimo è l'elemento di questo scope.

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

### scope.plugin

Type: `property`

Il [Plugin](../plugin/) collegato allo scope.

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

### scope.makepath(path)

Type: `method`

Risolve un path relativo allo scope.

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

Returns: `String` Il path risolto.

`?` è il path dello scope, `?1` è il path dello scope padre e `?2` è il path di due livelli sopra. Quando quel livello non esiste, viene usato il path dello scope.

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

### scope.get([path])

Type: `method`

Legge un path relativo allo scope.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `path` | `String` | no |  | Il path relativo. |

Returns: `Object` Il valore.

Senza argomenti, il metodo restituisce l'intero modello.

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

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

Type: `method`

Scrive un valore in un path relativo allo scope.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `path` | `String` | yes |  | Il path relativo. |
| `value` | `Object` | yes |  | Il valore. |
| `timeout` | `Number` | no |  | Un valore pari o superiore a `10` ritarda la modifica di quel numero di millisecondi. Un valore inferiore è il tipo della modifica. |
| `reset` | `Boolean` | no |  | `true` reimposta lo stato dopo una modifica ritardata. |

Example: Uso di 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`

Aggiunge un elemento a un array relativo allo scope.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `path` | `String` | yes |  | Il path relativo. |
| `value` | `Object` | yes |  | L'elemento. |
| `timeout` | `Number` | no |  | Un valore pari o superiore a `10` ritarda la modifica di quel numero di millisecondi. Un valore inferiore è il tipo della modifica. |
| `reset` | `Boolean` | no |  | `true` reimposta lo stato dopo una modifica ritardata. |

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

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

Type: `method`

Notifica i listener di un path relativo allo scope.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `path` | `String` | no |  | Il path relativo. |
| `timeout` | `Number` | no |  | Un valore pari o superiore a `10` ritarda la modifica di quel numero di millisecondi. Un valore inferiore è il tipo della modifica. |
| `reset` | `Boolean` | no |  | `true` reimposta lo stato. |

Example: Uso di 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`

Segna i componenti di un path come toccati e modificati.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `path` | `String` | no |  | Il path relativo. |

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

### scope.reset([path])

Type: `method`

Azzera lo stato dei componenti di un path.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `path` | `String` | no |  | Il path relativo. |

Lo stato di toccato e modificato viene azzerato. Il valore non cambia.

Example: Uso di 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`

Ripristina il valore predefinito dello scope.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `path` | `String` | no |  | Il path relativo. |
| `timeout` | `Number` | no |  | Il ritardo in millisecondi. |

Il valore predefinito proviene dall'attributo [`default`](../ui-plugin/#default) dell'elemento. Un numero come primo argomento è un ritardo in millisecondi.

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

### scope.can()

Type: `method`

Indica se i componenti dello scope possono essere salvati.

Returns: `Boolean` Il risultato.

Il risultato è `true` quando almeno un componente è toccato e nessuno è non valido. Uno scope senza componenti restituisce `true`.

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

### scope.errors()

Type: `method`

Restituisce i componenti toccati e non validi dello scope.

Returns: `Array` I componenti.

Example: Uso di 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`

Osserva un path relativo allo scope.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `path` | `String` | yes |  | Il path relativo. |
| `callback` | `Function` | yes |  | La funzione che riceve le modifiche. |
| `init` | `Boolean` | no |  | `true` chiama subito il callback. |

Returns: `Scope` Lo scope.

Il callback riceve `path`, `value` e `type`, e `this` è lo scope.

Example: Uso di 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`

Rimuove gli osservatori di un path.

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

Returns: `Scope` Lo scope.

Il metodo rimuove tutti gli osservatori che questo scope ha sul path.

Example: Uso di 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`

Rende attivo lo scope.

Returns: `Scope` Lo scope.

Funzioni come `SET()` sostituiscono allora `?` con il path di questo scope.

Example: Uso di 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`

Trova i componenti dentro lo scope.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `selector` | `String` | yes |  | Il selettore del componente. |
| `many` | `Boolean` | no |  | `true` restituisce un array. |
| `callback` | `Function` | no |  | Attende il componente e lo riceve. |
| `timeout` | `Number` | no |  | L'attesa massima in millisecondi. |

Returns: `Component|Array` Il risultato.

Gli argomenti sono gli stessi dell'estensione jQuery `FIND()`.

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

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

Type: `method`

Chiama un metodo dei componenti dentro lo scope.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `selector` | `String` | yes |  | Il selettore del componente. |
| `method` | `String` | yes |  | Il nome del metodo. |
| `args` | `Object` | no |  | Gli argomenti. |

Example: Uso di 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`

Riconfigura i componenti dentro lo scope.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `selector` | `String` | yes |  | Il selettore del componente. |
| `value` | `String|Object` | yes |  | La configurazione. |

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

### scope.find(selector)

Type: `method`

Trova gli elementi annidati.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `selector` | `String|Object` | yes |  | Un selettore o un oggetto di selettori. |

Returns: `jQuery|Object` Il risultato.

Un oggetto di selettori restituisce un oggetto di risultati jQuery con le stesse chiavi.

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

### scope.closest(selector)

Type: `method`

Trova il genitore corrispondente più vicino all'elemento.

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

Returns: `jQuery` Il risultato.

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

### scope.append(value)

Type: `method`

Aggiunge contenuto alla fine dell'elemento.

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

Returns: `jQuery` L'elemento.

Un array viene unito.

Example: Uso di 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`

Collega un evento jQuery all'elemento.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | Il nome dell'evento. |
| `selector` | `String` | no |  | Il selettore delegato. |
| `callback` | `Function` | yes |  | Il gestore. |

Returns: `Scope` Lo scope.

Gli argomenti sono gli stessi del metodo jQuery `on()`.

Example: Uso di 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`

Legge o scrive un attributo dell'elemento.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | L'attributo. |
| `value` | `String` | no |  | Il nuovo valore. |

Returns: `String|Scope` Il valore, oppure lo scope quando passi `value`.

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

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

Type: `method`

Legge o scrive un attributo `data-` dell'elemento.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | Il nome senza il prefisso `data-`. |
| `value` | `String` | no |  | Il nuovo valore. |

Returns: `String|Scope` Il valore, oppure lo scope quando passi `value`.

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

### scope.attrd2(name)

Type: `method`

Legge un attributo `data-` dall'elemento o dal genitore più vicino che lo possiede.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | Il nome senza il prefisso `data-`. |

Returns: `String` Il valore.

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

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

Type: `method`

Legge o scrive una proprietà CSS dell'elemento.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | La proprietà. |
| `value` | `String` | no |  | Il nuovo valore. |

Returns: `String|Scope` Il valore, oppure lo scope quando passi `value`.

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

### scope.autofocus([selector])

Type: `method`

Sposta il focus sul primo campo visibile dell'elemento.

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

Returns: `Scope` Lo scope.

Sui dispositivi mobili il metodo non fa nulla.

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

### scope.remove()

Type: `method`

Rimuove lo scope, il relativo elemento e i relativi componenti.

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