0
私のデータストアはアイテムの配列で構成されており、アイテムがアレイに追加または削除されたときに通知を受けたいと思います。これどうやってするの?私はデータ全体でプロパティオブジェクトを抽出しようとしましたが、失敗しました。dstoreのルートオブジェクトの変更をどのように観察できますか?
<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",
});
validatingMemory2.setData([{ "id": "one", "positionX": 100, "positionY": 200, "moduleType": "label" }]);
console.log(validatingMemory2);
//error: property is not a function
var prpertyObject = validatingMemory2..property("items");
//I want to be alerted here when the item is added
validatingMemory2.addSync({ "id": "two", "positionX": 300, "positionY": 400, "moduleType": "label" });
console.log(validatingMemory2);
});
</script>