dojo - dstore add() not adding new items to data store -


when try add new item data store, not add it. accepts data item set using setdata, , able work object including value, observe property etc.

how add additional items data store?

my code below.

<script>      require(         [         'dojo/_base/declare',         'dstore/memory',         'dmodel/extensions/jsonschema',         'dmodel/validators/stringvalidator',         'dmodel/store/validating',         "dmodel/model",         "dojox/json/schema",         "dojo/text!app/model/testing/baseschema.json",         ],      function (declare, memory, jsonschema, stringvalidator, validating, model, djs, myschema) {           var validatingmemory2 = (declare([memory, validating]))({             model: jsonschema(                 {                     "$schema": "http://json-schema.org/draft-04/schema#",                     "title": "form elements",                     "type": "array",                     "items": {                         "title": "form element",                         "type": "object",                         "properties": {                             "id": {                                 "description": "identifier",                                 "type": "string"                             },                              "positionx": {                                 "type": "number"                             },                              "positiony": {                                 "type": "number"                             },                             "moduletype": {                                 "description": "type",                                 "type": "string"                             }                          },                         "required": ["id"],                         "additionalproperties": false                     }                 }                  ),              idproperty: "id",              //additionalproperties: false //this indicates whether or not allow additional properties outside of defined schema. defaults true.         });           validatingmemory2.setdata([{ "id": "one", "positionx": 100, "positiony": 200, "moduletype": "label" }]);         console.log(validatingmemory2);          validatingmemory2.add({ "id": "two", "positionx": 300, "positiony": 400, "moduletype": "label" }); //does not add 1          console.log(validatingmemory2);          var objectone = validatingmemory2.getsync("one");         console.log(objectone.positionx); //100         var objecttwo = validatingmemory2.getsync("two");         console.log(objecttwo.positionx); //error undefined property          var propone = objectone.property("positionx");          propone.observe(function () {             console.log("updated");         });          propone.put(150);     }); </script> 

the dstore.add method returns promise , not add immediately.

add(object, [directives]) - creates object, , throws error if object exists. should return promise newly created object.

you need wait add complete.

validatingmemory2.add({ "id": "two",                          "positionx": 300,                          "positiony": 400,                          "moduletype": "label" }).then(function(){     var objecttwo = validatingmemory2.getsync("two");     console.log(objecttwo.positionx); }); 

or use sync methods add synchronously.

stores can perform synchronous operations may provide analogous methods get, put, add, , remove end sync provide synchronous support. example getsync(id) directly return object instead of promise. dstore/memory store provides sync methods

validatingmemory2.addsync({ "id": "two", "positionx": 300, "positiony": 400, "moduletype": "label" }); 

Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -