Scope
Le proprietà e i metodi di un oggetto scope.
In questa pagina
API
property
scope.path
Il path assoluto dello scope.
scope.pathvar scope = $('span').last().scope();
console.log(scope.path); // users
property
scope.id
L'identificatore univoco generato dello scope.
scope.idLo stesso valore è disponibile come ID.
var scope = $('span').last().scope();
console.log(scope.id === scope.ID); // true
property
scope.element
L'elemento dello scope come oggetto jQuery.
scope.elementvar scope = $('span').last().scope();
console.log(scope.element.prop('tagName')); // UI-PLUGIN
property
scope.config
La configurazione analizzata dell'elemento.
scope.configvar scope = $('span').last().scope();
console.log(scope.config.limit); // 10
property
scope.parent
Lo scope padre.
scope.parentLa proprietà è undefined per uno scope senza padre.
var scope = $('span').last().scope();
console.log(scope.parent.path); // users
property
scope.isolated
Indica se il path ignora lo scope padre.
scope.isolatedvar scope = $('span').last().scope();
console.log(scope.isolated); // false
property
scope.elements
Gli elementi degli scope padre e di questo scope.
scope.elementsGli elementi sono nodi DOM e l'ultimo è l'elemento di questo scope.
var scope = $('span').last().scope();
console.log(scope.elements.length); // 2
property
scope.plugin
Il Plugin collegato allo scope.
scope.pluginvar scope = $('span').last().scope();
console.log(scope.plugin.name); // users
method
scope.makepath(path)
Risolve un path relativo allo scope.
scope.makepath(path)| Parametro | Tipo | Descrizione |
|---|---|---|
path |
String |
Il path. |
Restituisce 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.
var scope = $('ui-plugin').scope();
console.log(scope.makepath('?.name')); // users.name
method
scope.get([path])
Legge un path relativo allo scope.
scope.get([path])| Parametro | Tipo | Descrizione |
|---|---|---|
path? |
String |
Il path relativo. |
Restituisce Object Il valore.
Senza argomenti, il metodo restituisce l'intero modello.
var scope = $('ui-plugin').scope();
console.log(scope.get('page')); // 1
method
scope.set(path, value, [timeout], [reset])
Scrive un valore in un path relativo allo scope.
scope.set(path, value, [timeout], [reset])| Parametro | Tipo | Descrizione |
|---|---|---|
path |
String |
Il path relativo. |
value |
Object |
Il valore. |
timeout? |
Number |
Un valore pari o superiore a 10 ritarda la modifica di quel numero di millisecondi. Un valore inferiore è il tipo della modifica. |
reset? |
Boolean |
true reimposta lo stato dopo una modifica ritardata. |
var scope = $('ui-plugin').scope();
scope.set('page', 2);
console.log(GET('users.page')); // 2
method
scope.push(path, value, [timeout], [reset])
Aggiunge un elemento a un array relativo allo scope.
scope.push(path, value, [timeout], [reset])| Parametro | Tipo | Descrizione |
|---|---|---|
path |
String |
Il path relativo. |
value |
Object |
L'elemento. |
timeout? |
Number |
Un valore pari o superiore a 10 ritarda la modifica di quel numero di millisecondi. Un valore inferiore è il tipo della modifica. |
reset? |
Boolean |
true reimposta lo stato dopo una modifica ritardata. |
var scope = $('ui-plugin').scope();
scope.push('items', 'A');
console.log(scope.get('items')); // ["A"]
method
scope.update([path], [timeout], [reset])
Notifica i listener di un path relativo allo scope.
scope.update([path], [timeout], [reset])| Parametro | Tipo | Descrizione |
|---|---|---|
path? |
String |
Il path relativo. |
timeout? |
Number |
Un valore pari o superiore a 10 ritarda la modifica di quel numero di millisecondi. Un valore inferiore è il tipo della modifica. |
reset? |
Boolean |
true reimposta lo stato. |
var scope = $('ui-plugin').scope();
scope.watch('page', (path, value) => console.log(value)); // 5
window.users.page = 5;
scope.update('page');
method
scope.change([path])
Segna i componenti di un path come toccati e modificati.
scope.change([path])| Parametro | Tipo | Descrizione |
|---|---|---|
path? |
String |
Il path relativo. |
var scope = $('ui-plugin').scope();
scope.change();
console.log(FIND('field').config.touched); // true
method
scope.reset([path])
Azzera lo stato dei componenti di un path.
scope.reset([path])| Parametro | Tipo | Descrizione |
|---|---|---|
path? |
String |
Il path relativo. |
Lo stato di toccato e modificato viene azzerato. Il valore non cambia.
var scope = $('ui-plugin').scope();
var com = FIND('field');
com.modify('Peter');
scope.reset();
console.log(com.config.touched, com.config.modified); // false false
method
scope.default([path], [timeout])
Ripristina il valore predefinito dello scope.
scope.default([path], [timeout])| Parametro | Tipo | Descrizione |
|---|---|---|
path? |
String |
Il path relativo. |
timeout? |
Number |
Il ritardo in millisecondi. |
Il valore predefinito proviene dall'attributo default dell'elemento. Un numero come primo argomento è un ritardo in millisecondi.
var scope = $('ui-plugin').scope();
scope.set('page', 5);
scope.default();
console.log(scope.get('page')); // 1
method
scope.can()
Indica se i componenti dello scope possono essere salvati.
scope.can()Restituisce Boolean Il risultato.
Il risultato è true quando almeno un componente è toccato e nessuno è non valido. Uno scope senza componenti restituisce true.
var scope = $('ui-plugin').scope();
FIND('field').modify('Peter');
console.log(scope.can()); // true
method
scope.errors()
Restituisce i componenti toccati e non validi dello scope.
scope.errors()Restituisce Array I componenti.
var scope = $('ui-plugin').scope();
var com = FIND('field');
com.validate = value => !!value;
com.bind('touched');
com.validate2();
console.log(scope.errors().length); // 1
method
scope.watch(path, callback, [init])
Osserva un path relativo allo scope.
scope.watch(path, callback, [init])| Parametro | Tipo | Descrizione |
|---|---|---|
path |
String |
Il path relativo. |
callback |
Function |
La funzione che riceve le modifiche. |
init? |
Boolean |
true chiama subito il callback. |
Restituisce Scope Lo scope.
Il callback riceve path, value e type, e this è lo scope.
var scope = $('ui-plugin').scope();
scope.watch('page', (path, value) => console.log(path, value)); // users.page 2
scope.set('page', 2);
method
scope.unwatch(path)
Rimuove gli osservatori di un path.
scope.unwatch(path)| Parametro | Tipo | Descrizione |
|---|---|---|
path |
String |
Il path relativo. |
Restituisce Scope Lo scope.
Il metodo rimuove tutti gli osservatori che questo scope ha sul path.
var scope = $('ui-plugin').scope();
scope.watch('page', () => console.log('called'));
scope.unwatch('page');
scope.set('page', 2);
console.log('end'); // end
method
scope.apply()
Rende attivo lo scope.
scope.apply()Restituisce Scope Lo scope.
Funzioni come SET() sostituiscono allora ? con il path di questo scope.
var scope = $('ui-plugin').scope();
scope.apply();
SET('?.page', 3);
console.log(GET('users.page')); // 3
method
scope.FIND(selector, [many], [callback], [timeout])
Trova i componenti dentro lo scope.
scope.FIND(selector, [many], [callback], [timeout])| Parametro | Tipo | Descrizione |
|---|---|---|
selector |
String |
Il selettore del componente. |
many? |
Boolean |
true restituisce un array. |
callback? |
Function |
Attende il componente e lo riceve. |
timeout? |
Number |
L'attesa massima in millisecondi. |
Restituisce Component|Array Il risultato.
Gli argomenti sono gli stessi dell'estensione jQuery FIND().
var scope = $('ui-plugin').scope();
console.log(scope.FIND('field').name); // field
method
scope.SETTER(selector, method, [...args])
Chiama un metodo dei componenti dentro lo scope.
scope.SETTER(selector, method, [...args])| Parametro | Tipo | Descrizione |
|---|---|---|
selector |
String |
Il selettore del componente. |
method |
String |
Il nome del metodo. |
args? |
Object |
Gli argomenti. |
var scope = $('ui-plugin').scope();
scope.SETTER('field/reconfigure', 'title:Orders');
console.log(FIND('field').config.title); // Orders
method
scope.RECONFIGURE(selector, value)
Riconfigura i componenti dentro lo scope.
scope.RECONFIGURE(selector, value)| Parametro | Tipo | Descrizione |
|---|---|---|
selector |
String |
Il selettore del componente. |
value |
String|Object |
La configurazione. |
var scope = $('ui-plugin').scope();
scope.RECONFIGURE('field', 'title:Orders');
console.log(FIND('field').config.title); // Orders
method
scope.find(selector)
Trova gli elementi annidati.
scope.find(selector)| Parametro | Tipo | Descrizione |
|---|---|---|
selector |
String|Object |
Un selettore o un oggetto di selettori. |
Restituisce jQuery|Object Il risultato.
Un oggetto di selettori restituisce un oggetto di risultati jQuery con le stesse chiavi.
var scope = $('ui-plugin').scope();
console.log(scope.find('span').length); // 1
method
scope.closest(selector)
Trova il genitore corrispondente più vicino all'elemento.
scope.closest(selector)| Parametro | Tipo | Descrizione |
|---|---|---|
selector |
String |
Il selettore. |
Restituisce jQuery Il risultato.
var scope = $('ui-plugin').scope();
console.log(scope.closest('body').length); // 1
method
scope.append(value)
Aggiunge contenuto alla fine dell'elemento.
scope.append(value)| Parametro | Tipo | Descrizione |
|---|---|---|
value |
String|Array |
Il contenuto. |
Restituisce jQuery L'elemento.
Un array viene unito.
var scope = $('ui-plugin').scope();
scope.append('<b>A</b>');
console.log(scope.find('b').text()); // A
method
scope.event(name, [selector], callback)
Collega un evento jQuery all'elemento.
scope.event(name, [selector], callback)| Parametro | Tipo | Descrizione |
|---|---|---|
name |
String |
Il nome dell'evento. |
selector? |
String |
Il selettore delegato. |
callback |
Function |
Il gestore. |
Restituisce Scope Lo scope.
Gli argomenti sono gli stessi del metodo jQuery on().
var scope = $('ui-plugin').scope();
scope.event('click', 'span', () => console.log('clicked')); // clicked
scope.find('span').click();
method
scope.attr(name, [value])
Legge o scrive un attributo dell'elemento.
scope.attr(name, [value])| Parametro | Tipo | Descrizione |
|---|---|---|
name |
String |
L'attributo. |
value? |
String |
Il nuovo valore. |
Restituisce String|Scope Il valore, oppure lo scope quando passi value.
var scope = $('ui-plugin').scope();
scope.attr('title', 'Users');
console.log(scope.attr('title')); // Users
method
scope.attrd(name, [value])
Legge o scrive un attributo data- dell'elemento.
scope.attrd(name, [value])| Parametro | Tipo | Descrizione |
|---|---|---|
name |
String |
Il nome senza il prefisso data-. |
value? |
String |
Il nuovo valore. |
Restituisce String|Scope Il valore, oppure lo scope quando passi value.
var scope = $('ui-plugin').scope();
scope.attrd('id', '5');
console.log(scope.attr('data-id')); // 5
method
scope.attrd2(name)
Legge un attributo data- dall'elemento o dal genitore più vicino che lo possiede.
scope.attrd2(name)| Parametro | Tipo | Descrizione |
|---|---|---|
name |
String |
Il nome senza il prefisso data-. |
Restituisce String Il valore.
var scope = $('ui-plugin').scope();
console.log(scope.attrd2('area')); // main
method
scope.css(name, [value])
Legge o scrive una proprietà CSS dell'elemento.
scope.css(name, [value])| Parametro | Tipo | Descrizione |
|---|---|---|
name |
String |
La proprietà. |
value? |
String |
Il nuovo valore. |
Restituisce String|Scope Il valore, oppure lo scope quando passi value.
var scope = $('ui-plugin').scope();
scope.css('display', 'block');
console.log(scope.css('display')); // block
method
scope.autofocus([selector])
Sposta il focus sul primo campo visibile dell'elemento.
scope.autofocus([selector])| Parametro | Tipo | Descrizione |
|---|---|---|
selector? |
String |
I campi. Predefinito: input,select,textarea |
Restituisce Scope Lo scope.
Sui dispositivi mobili il metodo non fa nulla.
var scope = $('ui-plugin').scope();
scope.autofocus();
console.log(document.activeElement.tagName); // INPUT
method
scope.remove()
Rimuove lo scope, il relativo elemento e i relativi componenti.
scope.remove()var scope = $('ui-plugin').scope();
scope.remove();
console.log($('ui-plugin').length); // 0