我一直在尝试用一个普通的模型来创建两个集合。我得到了以下错误:
"Uncaught enyo.Store.addRecord:添加到存储类app.ImageModel的重复记录,primaryKey设置为id,而67774271的值相同,如果没有将存储的ignoreDuplicates标志设置为true,则无法共存。“
以下是我定义的两个集合..。
enyo.kind({
name: "app.FeatureCollection",
kind: "enyo.Collection",
model: "app.ImageModel",
defaultSource: "appF",
...
...
});
enyo.kind({
name: "app.SearchCollection",
kind: "enyo.Collection",
model: "app.ImageModel",
defaultSource: "appS",
...
...
});我所使用的模型如下:
enyo.kind({
name: "app.ImageModel",
kind: "enyo.Model",
readOnly: true,
....
....
});有一次,我是这样设置的:
this.set("data", new app.FeatureCollection());而在另一个,
this.set("data", new app.SearchCollection());我无法找出什么会产生错误。我甚至尝试将"ignoreDuplicates“设置为model...but中的true,但错误还是出现了。任何我可能出错的建议。
发布于 2014-04-21 20:07:37
ignoreDuplicates标志应该设置在enyo.Store上,而不是enyo.Model上。
enyo.store.ignoreDuplicates = true;您是否使用fetch方法enyo.Collection来检索数据?如果是这样的话,您可以考虑在获取调用中将strategy属性设置为merge,这样您就可以为数据集中的每个唯一图像创建一个记录,即:
myCollection.fetch({strategy: "merge", success: function(rec, opts, res) {
// do something after data is retrieved
}});发布于 2014-04-21 21:22:22
我没有发现你提供的代码片段有问题。我在jsFiddle上创建了一个示例,它按预期工作。
http://jsfiddle.net/z7WwZ/
也许问题在你的代码的其他部分?
enyo.kind({
name: "app.FeatureCollection",
kind: "enyo.Collection",
model: "app.MyModel"
});
enyo.kind({
name: "app.SearchCollection",
kind: "enyo.Collection",
model: "app.MyModel"
});
enyo.kind({
name: "app.MyModel",
kind: "enyo.Model",
readOnly: true,
defaults: {
firstName: "Unknown",
lastName: "Unknown"
}
});
enyo.kind({
name: "App",
components: [],
bindings: [],
create: enyo.inherit(function (sup) {
return function () {
sup.apply(this, arguments);
this.collection1 = new app.FeatureCollection(this.data1);
enyo.log("Collection1(0) >>> " + this.collection1.at(0).get("lastName"));
this.collection1.at(0).set("lastName", "Smith");
enyo.log("Collection1(0) >>> " + this.collection1.at(0).get("lastName"));
this.collection2 = new app.SearchCollection(this.data2);
enyo.log("Collection2(0) >>> " + this.collection2.at(0).get("lastName"));
this.collection1.at(0).set("lastName", "Jones");
enyo.log("Collection2(0) >>> " + this.collection1.at(0).get("lastName"));
};
}),
data1: [{
firstName: "Hall",
lastName: "Caldwell"
}, {
firstName: "Felicia",
lastName: "Fitzpatrick"
}, {
firstName: "Delgado",
lastName: "Cole"
}],
data2: [{
firstName: "Alejandra",
lastName: "Walsh"
}, {
firstName: "Marquez",
lastName: "James"
}, {
firstName: "Barr",
lastName: "Lott"
}]
});
new App().renderInto(document.body);https://stackoverflow.com/questions/23197081
复制相似问题