-
7 Jan 2013 8:48 PM #1
Answered: Populating a form with multiple associated models
Answered: Populating a form with multiple associated models
I am trying to take advantage of Sencha Touch 2's ability to handle associated models. In my case, suppose I have a Selection and Book: Selection <<--> Book. So, I have a record that could look like this:
Suppose I want to populate a FormPanel with a Selection record. When it's a flat record, there's lots of documentation about this on the Internet, and I've gotten it to work easily:Code:{ id: 123, position: 1, book: { title: 'War and Peace' } }
When a form covers two associated models at once, this no longer works. A field dedicated to, say, book.title remains empty:Code:myFormPanel.setRecord(record);
Is there a way to populate Sencha Touch 2 forms automatically when the record is not flat? I could, of course, create a flat model specifically for this form, but that sort of defeats the purpose.Code:{ xtype: 'textfield', name: 'title', // also tried 'book.title' label: 'Title' }
If there's no automated way, what's the next best alternative? Individually fetching fields from the FormPanel and setting their values?Last edited by woram; 7 Jan 2013 at 8:52 PM. Reason: code tags got lost
-
Best Answer Posted by mitchellsimoens
You won't be able to do it that way. What you will need to do is create a flat object using the getters from the association so you get something like
Code:{ firstname : '....', lastname : '....' }
-
9 Jan 2013 8:55 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 34,121
- Vote Rating
- 453
- Answers
- 3160
You won't be able to do it that way. What you will need to do is create a flat object using the getters from the association so you get something like
Code:{ firstname : '....', lastname : '....' }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.
-
10 Jan 2013 8:32 AM #3
-
10 Jan 2013 9:12 AM #4Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 34,121
- Vote Rating
- 453
- Answers
- 3160
Use setValues method
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.
-
10 Jan 2013 10:25 AM #5
Oh, wow! I wish I had known about this weeks ago. Thanks.




Reply With Quote