-
14 Jan 2013 7:41 AM #1
Answered: Button + Ext.List + Ext.navigation.View + Panel = I need some help
Answered: Button + Ext.List + Ext.navigation.View + Panel = I need some help
Hello!
Kategori.png
First, I have a button with an ID that is linked to a view that lists the data from JSON (see code below):
Kategorilista.pngCode:Ext.define('LG.view.categories', { extend: 'Ext.List', xtype: 'categories', requires: [ 'Ext.dataview.List', 'Ext.data.proxy.JsonP', 'Ext.data.Store' ], config: { title: 'Kategorier', cls: 'categories', indexBar: true, itemTpl: '<h2 class="YrkesBenamning">{YrkesBenamning}</h2>', onItemDisclosure: true, store: { autoLoad: true, fields: ['YrkesId', 'YrkesBenamning', 'antal'], grouper: { groupFn: function(record) { return record.get('YrkesBenamning')[0]; } }, proxy: { type: 'jsonp', url: 'http://api.xxx.se/API.mvc/GetLillaGulaYrken?apikey=XXX', reader: { type: 'json', rootProperty: 'responseData.feed.entries' } } } } });
When you click on an item to activate the function in my controller, see code below:
KategoriVald.pngCode:showCompany: function(list, index, element, record) { var YrkesId = record.get('YrkesId'); console.log('id:' + YrkesId); /* * * Here I want to send the ID number to the next view, how do I do that? * */ var companylistView = new Ext.create('LG.view.companylist'); companylistView.setRecord(YrkesId); Ext.Viewport.setActiveItem(companylistView); }
In this function I create also a new view called 'companlistView' and contains the following code below. Right now I manually added an ID number (10) for the JSON stream, such as: http://api.xxx.se/API.mvc/GetLillaGulaKunderByYrkeId/10?apikey=xxx
But I need to get the ID number automatically for each item when you select a category, how do I do that? Do you understand what I mean?
Foeretag.pngCode:Ext.define('LG.view.companylist', { extend: 'Ext.navigation.View', xtype: 'companylist', id: 'companyList', requires: [ 'Ext.dataview.List', 'Ext.data.proxy.JsonP', 'Ext.data.Store' ], config: { title: 'Sökresultat', cls: 'companylist', items: { xtype: 'list', //itemTpl: '<h2 class="KNamn">{KNamn}</h2><p class="KAdress"><a href="http://maps.apple.com/?q={KAdress}, {KPostNr} {KOrt}">{KAdress}<br>{KPostNr} {KOrt}</a></p>', itemTpl: '<h2 class="KNamn">{KNamn}</h2>', onItemDisclosure: true, title: 'Sökresultat', cls: 'categorylist', store: { autoLoad: true, fields: ['PhoneNumber', 'KNamn', 'KId', 'KAdress', 'KOrt', 'KPostNr'], proxy: { type: 'jsonp', url: 'http://api.xxx.se/API.mvc/GetLillaGulaKunderByYrkeId/10?apikey=xxx', reader: { type: 'json', rootProperty: 'responseData.feed.entries' } } } } } });
The last view is printed by means of a push (). Code below:
Please help me!Code:showCompanyDetails: function(list, index, element, record) { this.getCompanylist().push({ xtype: 'panel', title: record.get('KNamn'), html: '<p style="border:solid 1px red;"><a href="tel:' + record.get('PhoneNumber') + '">' + record.get('KNamn') + '<br>' + record.get('PhoneNumber') + '</a><p><p style="border:solid 1px green;"><a href="rmaps:ll=63.288303,18.70905">' + record.get('KAdress') + '<br>' + record.get('KPostNr') + ' ' + record.get('KOrt') + '</a><p>', scrollable: true, styleHtmlContent: true }); }
-
Best Answer Posted by mitchellsimoens
First, instead of this:
I would do this:Code:var companylistView = new Ext.create('LG.view.companylist'); companylistView.setRecord(YrkesId);
Then in the LG.view.companylist component you have access to the record (will get the id in a second). This means that you can now take action on that using the updateRecord...Code:var companylistView = Ext.create('LG.view.companylist', { //notice no new! record : record });
So the changes I made here is removed autoLoad from the store so we can handle loading, removed the url config from the proxy, added the updateRecord method to handle the record config or if you do a setRecord on this method. Now your store should load with the id in the URL. I also added a new config for apiKey to make it a little more elegant.Code:Ext.define('LG.view.companylist', { extend: 'Ext.navigation.View', xtype: 'companylist', requires: [ 'Ext.dataview.List', 'Ext.data.proxy.JsonP', 'Ext.data.Store' ], config: { title: 'Sökresultat', cls: 'companylist', apiKey : 'xxxx', items: { xtype: 'list', //itemTpl: '<h2 class="KNamn">{KNamn}</h2><p class="KAdress"><a href="http://maps.apple.com/?q={KAdress}, {KPostNr} {KOrt}">{KAdress}<br>{KPostNr} {KOrt}</a></p>', itemTpl: '<h2 class="KNamn">{KNamn}</h2>', onItemDisclosure: true, title: 'Sökresultat', cls: 'categorylist', store: { fields: ['PhoneNumber', 'KNamn', 'KId', 'KAdress', 'KOrt', 'KPostNr'], proxy: { type: 'jsonp', reader: { type: 'json', rootProperty: 'responseData.feed.entries' } } } } }, updateRecord : function(record) { var YrkesId = record.get('YrkesId'), list = this.down('list'), store = list.getStore(), proxy = store.getProxy() apiKey = this.getApiKey(); proxy.setUrl('http://api.xxx.se/API.mvc/GetLillaGulaKunderByYrkeId/' + YrkesId + '?apikey=' + apiKey); store.load(); } });
-
16 Jan 2013 9:01 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,624
- Vote Rating
- 434
- Answers
- 3104
First, instead of this:
I would do this:Code:var companylistView = new Ext.create('LG.view.companylist'); companylistView.setRecord(YrkesId);
Then in the LG.view.companylist component you have access to the record (will get the id in a second). This means that you can now take action on that using the updateRecord...Code:var companylistView = Ext.create('LG.view.companylist', { //notice no new! record : record });
So the changes I made here is removed autoLoad from the store so we can handle loading, removed the url config from the proxy, added the updateRecord method to handle the record config or if you do a setRecord on this method. Now your store should load with the id in the URL. I also added a new config for apiKey to make it a little more elegant.Code:Ext.define('LG.view.companylist', { extend: 'Ext.navigation.View', xtype: 'companylist', requires: [ 'Ext.dataview.List', 'Ext.data.proxy.JsonP', 'Ext.data.Store' ], config: { title: 'Sökresultat', cls: 'companylist', apiKey : 'xxxx', items: { xtype: 'list', //itemTpl: '<h2 class="KNamn">{KNamn}</h2><p class="KAdress"><a href="http://maps.apple.com/?q={KAdress}, {KPostNr} {KOrt}">{KAdress}<br>{KPostNr} {KOrt}</a></p>', itemTpl: '<h2 class="KNamn">{KNamn}</h2>', onItemDisclosure: true, title: 'Sökresultat', cls: 'categorylist', store: { fields: ['PhoneNumber', 'KNamn', 'KId', 'KAdress', 'KOrt', 'KPostNr'], proxy: { type: 'jsonp', reader: { type: 'json', rootProperty: 'responseData.feed.entries' } } } } }, updateRecord : function(record) { var YrkesId = record.get('YrkesId'), list = this.down('list'), store = list.getStore(), proxy = store.getProxy() apiKey = this.getApiKey(); proxy.setUrl('http://api.xxx.se/API.mvc/GetLillaGulaKunderByYrkeId/' + YrkesId + '?apikey=' + apiKey); store.load(); } });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.
-
17 Jan 2013 2:38 AM #3


Reply With Quote