यदि आप एक नया संग्रह सेट करके इस तरह के पूरे संबंध को रीसेट करते हैं, तो बैकबोन-रिलेशनल इच्छा (फिलहाल) अंतरों की जांच करने के बजाय, पूरे संग्रह को प्रतिस्थापित करें। तो यह सभी मौजूदा subModels
के लिए remove
ईवेंट आग लगाएगा, फिर प्रत्येक नए के लिए add
ईवेंट आग लगाना होगा।
मैं हालांकि change
घटनाओं मिलता है, निम्नलिखित कोड के साथ क्या (यदि पोस्ट कोड हालांकि पूर्ण उदाहरण में शामिल है यह मदद मिलेगी;)
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}] })
यह निम्न उत्पादन पैदावार:
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 {}]
हैं आप इन परिवर्तन घटनाओं को नहीं देखते हैं, क्या आप जांच सकते हैं कि रीढ़ की हड्डी और रीढ़ की हड्डी-रिलेशनल के कौन से संस्करण आप उपयोग कर रहे हैं?
तो मुझे लगता है कि मुझे पता चला है कि रीढ़ की हड्डी-रिलेशनल की बनाई गई मॉडल कार्यक्षमता पैरेंट मॉड्यूल में विशेषताओं के आगे सेट पर नेस्टेड मॉडल अपडेट नहीं करेगी। यह सिर्फ उन्हें पकड़ता है और नए जोड़ता है। तो यह कारण हो रहा था क्योंकि घटनाओं को केवल जोड़ना/निकालना घटनाओं को नहीं बदल रहा था। यही कारण है कि डेटा उन सभी घटनाओं को आग लगती है जब डेटा समान होता है। कम से कम यह मेरी सोच है अभी मुझे बताएं कि यह सही है या गलत है। धन्यवाद! – fancy