17 Apr 2014 12:00 PM #1
Unanswered: Listening model changes from a view model
I have a view model handling a model. On another view I have a grid showing records of the same model. The user can take action on records which will change the value of some field of the records.
How can I be notified when fields of the model of my view model changed?
In other words how can a view model listen changes from a model?
21 Apr 2014 5:16 AM #2
- Join Date
- Mar 2007
- Gainesville, FL
- Vote Rating
A ViewModel shouldn't have logic like this, a controller should. The issue is, Ext.data.Model doesn't fire events so there isn't a way to listen to events on it. You need to architect your app to work around this, kind of hard to help on that part as I'm not involved in your application.Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Software Engineer
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services email@example.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!
When posting code, please use BBCode's CODE tags.
22 Apr 2014 10:42 AM #3
Thank you for your answer. Handling my case in the view controller is certainly possible. I was thinking about model events because of the architecture schema I saw in the "What's new in Ext JS 5" article:
I may misunderstood something (I'm quite new in the Ext JS world) but the grid has a nice "getRowClass" functionality that is called each time a model changed to update the UI. However if I have other UI component in the application binding to the same data I want to make a view model but then I have one component depending on the model and others depending on the view model.
Here's some information about what I try to accomplish:
I have a grid with a master-detail panel. The grid has an action column with a Like and a Dislike button. The style of the buttons are different depending on a "preference" property on the model. For this I'm using the getClass support on the action column and each time the model preference changed the buttons style change automatically.
In the detail pane I also have the same two button. I have a view model for this. If the user click a button in the grid I want my panel to update. My first idea was to listen prefence change in the view model to update the UI but I can't do this. Sure I can have a view controller to inform the pane something happens but it would be nice to leverage the model here.
Thank for any advice!