Yeni bir koleksiyon belirleyerek o şekilde bir ilişkiyi sıfırlarsanız, o anda omurgaya ilişkisel irade (yalnızca), tüm farklılıkları kontrol etmek yerine tüm koleksiyonu değiştirin. Bu nedenle, tüm geçerli subModels
için bir remove
olayını tetikler, daha sonra her bir yenisi için add
olayını tetikler.
Aşağıdaki kod ile olsa change
olayları olsun; Bu aşağıdaki çıktıyı verir
var SubModel = Backbone.RelationalModel.extend({});
var TheModel = Backbone.RelationalModel.extend({
relations: [{
type: Backbone.HasMany,
key: 'subModels',
relatedModel: SubModel,
reverseRelation: {
key: 'TheModel'
}
}]
});
themodel = new TheModel({subModels: [{ id: 5 },{id: 7},{id: 8}]})
themodel.bind('change', function() {
console.debug('change; args=%o', arguments);
});
themodel.bind('change:subModels', function() {
console.debug('change:subModels; args=%o', arguments);
});
themodel.bind('update:subModels', function() {
console.debug('update:subModels; args=%o', arguments);
});
themodel.bind('add:subModels', function() {
console.debug('add:subModels; args=%o', arguments);
});
themodel.bind('remove:subModels', function() {
console.debug('remove:subModels; args=%o', arguments);
});
console.debug('set new subModels');
themodel.set({subModels: [{ id: 5 },{id: 7},{id: 9}] })
(yayınlanan kod olsa eksiksiz bir örnek içeriyorsa o yardımcı olacağını):
set new subModels
change:subModels; args=[Object { _queue={...}, attributes={...}, _escapedAttributes={...}, more...}, [Object { id=5}, Object { id=7}, Object { id=9}], Object {}]
change; args=[Object { _queue={...}, attributes={...}, _escapedAttributes={...}, more...}, undefined]
remove:subModels; args=[Object { _queue={...}, attributes={...}, _escapedAttributes={...}, more...}, Object { length=3, models=[3], _byId={...}, more...}, Object { _related={...}}]
remove:subModels; args=[Object { _queue={...}, attributes={...}, _escapedAttributes={...}, more...}, Object { length=3, models=[3], _byId={...}, more...}, Object { _related={...}}]
remove:subModels; args=[Object { _queue={...}, attributes={...}, _escapedAttributes={...}, more...}, Object { length=3, models=[3], _byId={...}, more...}, Object { _related={...}}]
add:subModels; args=[Object { _queue={...}, attributes={...}, _escapedAttributes={...}, more...}, Object { length=3, models=[3], _byId={...}, more...}, Object {}]
add:subModels; args=[Object { _queue={...}, attributes={...}, _escapedAttributes={...}, more...}, Object { length=3, models=[3], _byId={...}, more...}, Object {}]
add:subModels; args=[Object { _queue={...}, attributes={...}, _escapedAttributes={...}, more...}, Object { length=3, models=[3], _byId={...}, more...}, Object {}]
update:subModels; args=[Object { _queue={...}, attributes={...}, _escapedAttributes={...}, more...}, Object { length=3, models=[3], _byId={...}, more...}, Object {}]
ise Bu değişim olaylarını görmüyorsunuz, kullandığınız omurga ve omurga-ilişkisel sürümlerini kontrol edebilir misiniz?
Bu yüzden, omurga ilişkiselliğinin createModels işlevinin ana modüle başka nitelik kümeleri üzerinde yuvalanmış modelleri güncelleştirmeyeceğini düşündüm. Sadece onları karıştırır ve yenilerini ekler. Bu yüzden bunun sebebi, yalnızca etkinlik ekleme/çıkarma olaylarının değiştirilmemesiydi. Ayrıca, tüm bu olayların, veriler aynı olduğunda neden yangın çıkmasıdır. En azından bu benim düşüncem şu, bu doğru ya da yanlış olup olmadığını bana bildirin. Teşekkürler! – fancy