-
16 Mar 2012 1:49 AM #1
Answered: Change value of component in DataItem when using dataMap
Answered: Change value of component in DataItem when using dataMap
I have Ext.Img component in DataItem. After getting url value from server, I want to add url of Sencha.io to it. Then, I set it as Img component src.
Url value from server:
images/someimage.jpg
New url:
http://src.sencha.io/60/60/http://my.../someimage.jpg
Here is my code. It always gets the old value from server. Do anyone know the reason?
Btw, is there any better approach for this?
Code:Ext.define('ABC.view.HotDealItem', { extend : 'Ext.dataview.component.DataItem', xtype : 'hotdealitem', requires : ['Ext.Img'], config : { dataMap : { getImage : { setSrc : 'image' } }, image : { docked : 'left', xtype : 'image', cls : 'image' }, layout : { type : 'vbox' } }, applyImage : function(config) { return Ext.factory(config, Ext.Img, this.getImage()); }, updateImage : function(newImage, oldImage) { if(oldImage) { this.remove(oldImage); } if(newImage) { this.add(newImage); } }, updateRecord : function(newRecord) { this.callParent(arguments); if(!newRecord) { return; } var image = this.getImage(); image.setSrc('http://src.sencha.io/60/60/http://mydomain.com/' + newRecord.get('image')); } });
-
Best Answer Posted by mitchellsimoens
Why not use the convert config in the field in the model? Change the URL up front.
-
16 Mar 2012 6:03 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 34,121
- Vote Rating
- 453
- Answers
- 3160
Why not use the convert config in the field in the model? Change the URL up front.
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.
-
16 Mar 2012 8:12 PM #3
Use convert config to change or add new field to model
Use convert config to change or add new field to model
Thanks Mitchell.
I follow your suggestion, and it works now. I upload my code below. Maybe, it will be helpful for someone.
In the model, I still want to keep "image" field. Therefore, I create a new field named "image-s".
References:Code:Ext.define('ABC.model.HotDeal', { extend : 'Ext.data.Model', requires : 'ABC.proxy.HotDeal', config : { fields : [ { name : "image", type : "string" }, { name : "image-s", type : "string", convert : function(v, record) { return 'http://src.sencha.io/60/60/http:/mydomain.com/' + record.data.image; } } ], proxy : { type : 'hotdeal' } } });
http://docs.sencha.com/touch/2-0/#!/...ld-cfg-convert
-
23 Apr 2012 6:28 PM #4
I think that updateRecord is the right place to format the values for the dataitem. The representation of the data is a view logic, we should not do it in the domain models.
-
31 Jan 2013 7:24 AM #5
The updateRecord "way" works fine, especially after having removed the deprecated datamap config element.
Olivier - interfaSys
Developing custom solutions for BlackBerry 10 using Sencha Touch.
-
5 May 2013 10:05 PM #6
-
6 May 2013 6:18 AM #7Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 34,121
- Vote Rating
- 453
- Answers
- 3160
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.
-
6 May 2013 7:35 PM #8


Reply With Quote
