6
class TheModel extends Backbone.RelationalModel 
    relations:[ 
     type: Backbone.HasMany 
     key: 'subModels' 
     relatedModel: SubModel 
     collectionType: SubModels 
     reverseRelation: 
      key: 'TheModel' 
    ] 

themodel = new the TheModel({subModels:[{#stuff},{#stuff},{#stuff}]}) 

मैं createModels पर इतना themodel.get('subModels') मॉडल का एक संग्रह रिटर्न दिया है।बैकबोन रिलेशनल घटनाएं फायरिंग नहीं कर रही हैं?


mymodel

themodel.set({subModels:[{changedstuff},{stuff},{stuff}]}) 

में अब अगर मैं बदल जाते उप-मॉडल डेटा themodel एक change घटना नहीं फेंक देना चाहिए? यह मेरे लिए नहीं है।


अधिक इसलिए यदि मैं mymodel

themodel.set({subModels:[{samestuff},{samestuff},{samestuff}]}) 

themodel.attributes.subModels फेंकता add और update घटनाओं में समान डेटा पास है, भले ही कुछ भी नहीं नया है।

मुझे यकीन नहीं है कि ये समस्याएं क्यों हो रही हैं, कोई मदद महान होगी, धन्यवाद !!!!

+0

तो मुझे लगता है कि मुझे पता चला है कि रीढ़ की हड्डी-रिलेशनल की बनाई गई मॉडल कार्यक्षमता पैरेंट मॉड्यूल में विशेषताओं के आगे सेट पर नेस्टेड मॉडल अपडेट नहीं करेगी। यह सिर्फ उन्हें पकड़ता है और नए जोड़ता है। तो यह कारण हो रहा था क्योंकि घटनाओं को केवल जोड़ना/निकालना घटनाओं को नहीं बदल रहा था। यही कारण है कि डेटा उन सभी घटनाओं को आग लगती है जब डेटा समान होता है। कम से कम यह मेरी सोच है अभी मुझे बताएं कि यह सही है या गलत है। धन्यवाद! – fancy

उत्तर

0

यदि आप एक नया संग्रह सेट करके इस तरह के पूरे संबंध को रीसेट करते हैं, तो बैकबोन-रिलेशनल इच्छा (फिलहाल) अंतरों की जांच करने के बजाय, पूरे संग्रह को प्रतिस्थापित करें। तो यह सभी मौजूदा 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 {}] 

हैं आप इन परिवर्तन घटनाओं को नहीं देखते हैं, क्या आप जांच सकते हैं कि रीढ़ की हड्डी और रीढ़ की हड्डी-रिलेशनल के कौन से संस्करण आप उपयोग कर रहे हैं?

+0

मुझे बैकबोन 0.5.3 और बैकबोन-रिलेशनल 0.4.0 पर एक ही समस्या है - माता-पिता संबंधों पर ईवेंट आग जोड़ें और निकालें। परिवर्तन कुछ नहीं करते हैं। –

संबंधित मुद्दे

 संबंधित मुद्दे