从dojo/store/Memory
源代码:
// idProperty: String
// Indicates the property to use as the identity property. The values of this
// property should be unique.
idProperty: "id",
getIdentity: function(object){
// summary:
// Returns an object's identity
// object: Object
// The object to get the identity from
// returns: Number
return object[this.idProperty];
IE:
var id = 1;
store.getIdentity(store.get(id)) == id;
您当然可以定义自己的idProperty
:
var store = new dojo.store.Memory({
data: [
{id: 1, name: "store1_item1", prime: false},
{id: 2, name: "store1_item2", prime: true},
{id: 3, name: "store1_item3", prime: true},
{id: 4, name: "store1_item4", prime: false},
{id: "xy", name: "store1_item5", prime: true}
],
idProperty: "name"
});
然后:
var item = store.get("store1_item1"); // item == {id: 1, name: "store1_item1", prime: false}
store.getIdentity(item) == "store1_item1";
基本上,它应该返回primary key
从存储中检索到的对象的 a。