I seem to have created a circular reference, with 2 listeners which respond to changes in 2 separate models, but unfortunately update each other.
The parent object ‘FleetQuote’ updates the child object ‘Sectors’. The first listener listens for changes in the FleetQuote model, and updates the Sectors if changes occur.
The child object ‘Sectors’ updates the parent object with e.g. a Final Price (sum of the sectors), and I have a listener which listens for those changes in the sector and updates the quote.
But one obviously updates the other!
Code is below:
//listener for Fleet Quote model
skuid.$(function(){
var FleetQuote = skuid.model.getModel(‘FleetQuote’),
FleetQuoteSectors = skuid.model.getModel(‘FleetQuoteSectors’);
var listener = new skuid.ui.Editor();
listener.handleSave = function() {
if (!FleetQuote.hasChanged) {
FleetQuoteSectors.updateData();
}
};
listener.registerModel(FleetQuote);
});
//listener for sectors Model
skuid.$(function(){
var FleetQuoteSectors = skuid.model.getModel(‘FleetQuoteSectors’),
FleetQuote = skuid.model.getModel(‘FleetQuote’);
var listener = new skuid.ui.Editor();
listener.handleSave = function() {
if (!FleetQuoteSectors.hasChanged) {
FleetQuote.updateData();
}
};
listener.registerModel(FleetQuoteSectors);
});
The only solution I can think of is that I only really need to listen to changes on specific fields in the quote model (rather than the whole model) but how do I implement a listener for 2 or 3 specific fields on a model?
Any help is GREATLY appreciated! Greg
Question
circular reference with 2 listeners
This topic has been closed for replies.
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.
,