dojo deferred stateful

Dojo Stateful watch method dispara antes de que el valor se establezca



deferred (1)

después de una discusión con richard sobre irc, pudimos descubrir que había algún matiz entre dojox.data.QueryReadStore y dijit.form.FilteringSelect que impedía que se dijit.form.FilteringSelect la devolución de llamada de "value" si la tienda aún no había hecho una fetch . la solución de trabajo era hacer una fetch primero y luego crear el widget en la onComplete llamada onComplete - ver http://jsfiddle.net/neonstalwart/dEC7M/

la parte relevante es

customerAddressesPairsView.fetch({ onComplete: function() { var w = new dijit.form.FilteringSelect({ name: ''source_address_id'', required: true, store: customerAddressesPairsView, searchAttr: "name", style: "width: 40ex;" }, ''sourceAddress''); var handle = w.watch(function(property, oldValue, newValue) { console.log(property, oldValue, newValue); }); w.set("value", value1); console.debug(''Value set to '' + value1); console.debug(''Immediate get returns:'', w.get(''value'')); console.debug(''Direct access returns: '' + w.value); } });

Usando Dojo 1.6.1.

Actualización: Aquí un jsfiddle http://jsfiddle.net/E4EaM/1/

Se crea un formulario con algunos campos.

this.projectServiceidField = new dijit.form.TextBox({ label: ''idField'' , name: ''project_service_id'' , required: true , type: ''hidden'' }).placeAt(this.domNode); this.projectServiceEquipmentSourceAddress = new dijit.form.FilteringSelect({ name: ''source_address_id'' , required: true , store: model.CustomerAddressesPairsView , searchAttr: "name" , style: "width: 40ex;" });

La aplicación debe ser notificada cuando se hayan establecido todos los valores del widget. Para hacer esto, se crea un objeto aplazado con un reloj Stateful en la propiedad de valor del widget. Los objetos aplazados se colocan todos en una lista diferida. Una vez que el valor de un widget se ha establecido inicialmente, se retira el reloj y se resuelve el objeto diferido.

//loop w.deferred = new dojo.Deferred(); da.push(w.deferred); // Watch the widget''s value w.initWatch = w.watch(''value'', function(property, oldValue, newValue) { w.initWatch.unwatch(); console.debug(w.name, ''property:'', property, ''oldValue:'', oldValue,''newValue:'', newValue,''w.get(/'value/'):'', w.get(''value'')); w.deferred.resolve(); }); // Set the widget''s value w.set(''value'', value); //endloop var dl = new dojo.DeferredList(da);

Cuando se resuelva DeferredList, todos los valores del widget deberían haberse establecido.

dl.then( function() { dojo.forEach(da, function(d) { console.debug(Date.now(), d); }) console.debug(Date.now(), dl, ''DeferredList resolved -------->'', form.getValues()); console.debug(form.getValues()); } );

Pero, no funciona como se esperaba. Específicamente los campos que hacen solicitudes xhr. Aquí están los valores generados en los eventos de cambio de ''valor''.

propiedad project_service_id : value oldValue: newValue: 1025 w.get (''value''): 1025

propiedad source_address_id : valor oldValue: newValue: 59 w.get (''valor''):

source_address_id se suponía que tenía un valor 59, pero cuando w.get (''valor''), no es igual a newValue. ¿No deberían ser?

¿Cómo puedo determinar cuándo se ha establecido el valor de un widget? ¿Por qué no es value == w.get (''value'') inmediatamente después de w.set (''value'', value)?

Si w.set (''value'', value) no está realmente configurando el valor, ¿no debería devolver un diferido?

¿No debería mirar solo el fuego después de establecer el valor?

Versiones de Dojo:

Falla en Dojo 1.6.1. Watch no siempre dispara y w.get (''value'')! = NewValue cuando lo hace.

Falla menos en Dojo 1.7.2. El reloj aún no siempre se dispara, pero al menos w.get (''value'') == newValue.