-
19 Nov 2012 1:19 PM #1
Answered: Cannot get simple belongsTo sample code to work?
Answered: Cannot get simple belongsTo sample code to work?
I've tried two different examples of a simple belongsTo "getter" and both of them yield the error message "Uncaught Error: [ERROR][Anonymous] You are trying to load a model that doesn't have a Proxy specified"
One is in the API documentation for "belongsTo".
The other is a response in a forum thread.
I posted a question about using this in a list with the "prepareData" config property, but got no response. Now trying to use it in a non-list context. Does it actually work. Can someone point me to a working examples?
Any other suggestions? Thanks.
-
Best Answer Posted by mitchellsimoens
Working for me:
data/json.json:Code:Ext.define('Post', { extend : 'Ext.data.Model', config : { fields : ['id', 'user_id'], proxy : { type : 'ajax', url : 'data/json.json', reader : 'json' } } }); Ext.define('Comment', { extend : 'Ext.data.Model', config : { fields : ['id', 'user_id', 'post_id'], belongsTo : 'Post' } }); Ext.application({ name : 'Test', launch : function () { var comment = new Comment({ id : 1, user_id : 1, post_id : 1 }); comment.getPost({ callback : function (post) { console.log(post); } }); } });
Code:{ "id" : 1, "user_id" : 1 }
-
21 Nov 2012 6:19 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,714
- Vote Rating
- 438
- Answers
- 3113
Working for me:
data/json.json:Code:Ext.define('Post', { extend : 'Ext.data.Model', config : { fields : ['id', 'user_id'], proxy : { type : 'ajax', url : 'data/json.json', reader : 'json' } } }); Ext.define('Comment', { extend : 'Ext.data.Model', config : { fields : ['id', 'user_id', 'post_id'], belongsTo : 'Post' } }); Ext.application({ name : 'Test', launch : function () { var comment = new Comment({ id : 1, user_id : 1, post_id : 1 }); comment.getPost({ callback : function (post) { console.log(post); } }); } });
Code:{ "id" : 1, "user_id" : 1 }Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
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 services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
21 Nov 2012 7:34 AM #3
Thanks for taking the time to try it out. Must be something I'm not doing right. I'll go back and try a few more things.


Reply With Quote