-
31 Dec 2011 7:06 PM #1
Answered: Stuck - MVC Application Architecture guide does not save to server
Answered: Stuck - MVC Application Architecture guide does not save to server
I've run through the "MVC Application Architecture" guide very carefully, several times. I get the correct console messages and results as the guide progresses up to a certain point.
It stops working as described in the guide when I get to the "Saving to the Server" section. That is, the updateUsers.json data file does not have the expected dummy success response - the file is empty. The last entry in Chrome's network log is "dirty.gif" and not "updateUsers.json" as in the guide.
I added a console message to the updateUser function to make sure the code was being executed. It seems as if the "this.getUsersStore().sync();" line is not doing anything.
I would really like to have success with this guide before moving to the next step. Any gurus that can help?
-
Best Answer Posted by silentreproach
I found a solution. In the guide, there is a section called "Creating a Model and a Store". It describes how to edit app/view/user/List.js, as the guide says: "to simply reference the Store by id".
The guide was unclear how to edit List.js and in several attempts I did not edit it correctly. So, here is what I believe List.js should ultimately contain and which helped me get past my obstacle:
Code:Ext.define('AM.view.user.List' ,{ extend: 'Ext.grid.Panel', alias : 'widget.userlist', //we no longer define the Users store in the `initComponent` method store: 'Users', title : 'All Users', initComponent: function() { this.columns = [ {header: 'Name', dataIndex: 'name', flex: 1}, {header: 'Email', dataIndex: 'email', flex: 1} ]; this.callParent(arguments); } });
-
1 Jan 2012 12:24 AM #2
Can you post some of your source code. so we can walk through it and figure where is a problem. Mainly I'm interested in how did you define a store
-
1 Jan 2012 3:55 AM #3
Sure, here is my app\store\Users.js
and my app/controller/Users.js:Code:Ext.define('AM.store.Users', { extend: 'Ext.data.Store', model: 'AM.model.User', autoLoad: true, proxy: { type: 'ajax', api: { read: 'data/users.json', update: 'data/updateUsers.json' }, reader: { type: 'json', root: 'users', successProperty: 'success' } } });
If there's any other code you want, or there is a better way for me to post it, please let me know.Code:Ext.define('AM.controller.Users', { extend: 'Ext.app.Controller', stores: ['Users'], models: ['User'], views: [ 'user.List', 'user.Edit' ], init: function() { this.control({ 'viewport > userlist': { itemdblclick: this.editUser }, 'useredit button[action=save]': { click: this.updateUser } }); }, editUser: function(grid, record) { var view = Ext.widget('useredit'); view.down('form').loadRecord(record); }, updateUser: function(button) { var win = button.up('window'), form = win.down('form'), record = form.getRecord(), values = form.getValues(); record.set(values); win.close(); this.getUsersStore().sync(); } });
Screenshot of Chrome's debugger after updateUser function:
screenie.jpgLast edited by silentreproach; 2 Jan 2012 at 5:06 AM. Reason: added screenshot
-
2 Jan 2012 5:07 AM #4
Added code and screenshot. Still can't get the MVC Application Architecture guide to work as described. Anyone able to make it work?
-
2 Jan 2012 5:19 AM #5
Can you put a breakpoint to
this.getUsersStore().sync(); and trace down what it is doing ?
-
2 Jan 2012 6:41 AM #6
I found a solution. In the guide, there is a section called "Creating a Model and a Store". It describes how to edit app/view/user/List.js, as the guide says: "to simply reference the Store by id".
The guide was unclear how to edit List.js and in several attempts I did not edit it correctly. So, here is what I believe List.js should ultimately contain and which helped me get past my obstacle:
Code:Ext.define('AM.view.user.List' ,{ extend: 'Ext.grid.Panel', alias : 'widget.userlist', //we no longer define the Users store in the `initComponent` method store: 'Users', title : 'All Users', initComponent: function() { this.columns = [ {header: 'Name', dataIndex: 'name', flex: 1}, {header: 'Email', dataIndex: 'email', flex: 1} ]; this.callParent(arguments); } });
-
9 Jan 2012 9:41 AM #7
I have the exact same code as noted here but still don't see anything written to updateUsers.json.
-
11 Jan 2012 9:51 AM #8
Actually I had this problem also (nothing written to updateUsers.json), but I did not mention it. I did everything according to the tutorial and everything else worked as described except this last step. I still don't know why. Anyone else have this problem besides me and wxkevin?
-
14 Nov 2012 7:04 AM #9
Should it even get updated?
Should it even get updated?
This thread is marked "Answered" - was it really? I got stuck on the same last step - updating updateUsers.json file. Another thread on the same topic (http://www.sencha.com/forum/showthread.php?246809) suggests that the file should not even get updated following just the tutorial's steps. Instead, you need to send the request to a script to do the update. So should it or should it not get updated iff one follows the tutorial?
Thanks!


Reply With Quote