dojo 更改id属性值后,无法从数据存储中检索对象

91zkwejq  于 2022-12-16  发布在  Dojo
关注(0)|答案(1)|浏览(184)

对于以下只包含一个项目的数据存储区,

var Model = require('dmodel/Model');
     var Memory = require('dstore/Memory');
     var jsonSchema = require('dmodel/extensions/jsonSchema');
     var declare = require('dojo/_base/declare');

     var formStore = (declare([Memory]))({
            Model: jsonSchema(formSchema),
            idProperty: "formId",

     });

     var formProperties = {
            "formName": "formName",
            "formId": 'xyz',
            "formType": 'formType'
      };

      formStore.setData([formProperties]);

我想做以下事情

var item = formStore.getSync('xyz');

//get a property object from an data object,
var property = item.property('formId'); 

//request a change in the value of this property
property.put('abc');

formStore.getIdentity(formStore.data[0]) //returns 'abc'

**BUT**

formStore.getSync('abc')  //returns undefined, even though it shows as 'abc' in the data array.

即使属性的值发生了变化,我也无法通过新的ID检索它。

g2ieeal7

g2ieeal71#

你的代码看起来很混乱,但我似乎理解正确。从我的Angular 来看,你有两个选择:
1.使用另一个值作为idProperty,该值不会被更改;
1.删除初始项并使用新ID放置新项;
更改存储区中项目的ID是个坏主意。

相关问题