ONeill
17 Jun 2012, 8:30 AM
Hello guys,
i dispair at my problem :( I think its only a simple bug i have created in the code, but i don't find them :(
The Problem:
I have a data store:
Ext.create('Ext.data.Store', { id:'romStoreid', storeId:'romStore', fields:['id', 'name'], data:{'items':[ <?php $sql = mysql_query('SELECT id, name, lasttime, device FROM content WHERE access = "1"'); if (mysql_num_rows($sql) == 0) { echo 'No resources found.<br>'; } else { while ($c = mysql_fetch_array($sql)) { $device = mysql_query('SELECT deviceName FROM devices WHERE deviceID = "'.mysql_real_escape_string($c["device"]).'"'); $device = mysql_fetch_array($device); echo "{ 'id': '".$c[id]."', \"name\":\"".$device[deviceName]." ".$c[name]."\" },"; } } ?> ]}, proxy: { type: 'memory', reader: { type: 'json', root: 'items' } } });
and the data store is used for my grid:
{ id: 'testernavpanel', title: 'Available Roms', items: [{ xtype: 'grid', title: '', id: 'romGrid', store: Ext.data.StoreManager.lookup('romStore'), columns: [ { header: 'ID', dataIndex: 'id', hidden: true, hideable: false}, { header: 'Name', dataIndex: 'name', width: 240 } ], width: 250, renderTo: Ext.getCmp('testernavpanel'), }], iconCls: 'info' }
Now i have a refresh button. The task of this button is to delete all values in the store and load them new from another php file using ajax:
Ext.Ajax.request({ url: 'expand.php?view=testers_new', method: 'GET', callback: function(options, success, response) { var data = response.responseText; a.getStore().removeAll(); a.getStore().add(data); console.log(data); } });
The new data come from this php code:
$sql = mysql_query('SELECT id, name, device FROM content WHERE access = "1"'); if (mysql_num_rows($sql) == 0) { echo 'No resources found.<br>'; } else { while ($c = mysql_fetch_array($sql)) { $device = mysql_query('SELECT deviceName FROM devices WHERE deviceID = "'.mysql_real_escape_string($c["device"]).'"'); $device = mysql_fetch_array($device); echo "{id: '".$c[id]."', name: '".$device[deviceName]." ".$c[name]."'}, "; } echo "{id:'', name:\"\"}"; }
Now the big problem is, that after i clicked on refresh, all values will be removed, ok. But then only one empty value is added.
The json encoded data is correct transmitted from the php file, i have copied the data from the console and added them to the "a.getStore().add(data);" instead of "data". Then all is ok, and the new data is inserted as the new values.
Has anyone of you an idea why the data of the php file inserted in the store?
Thanks for help and if any more code is needed, please ask ;)
Greetings
i dispair at my problem :( I think its only a simple bug i have created in the code, but i don't find them :(
The Problem:
I have a data store:
Ext.create('Ext.data.Store', { id:'romStoreid', storeId:'romStore', fields:['id', 'name'], data:{'items':[ <?php $sql = mysql_query('SELECT id, name, lasttime, device FROM content WHERE access = "1"'); if (mysql_num_rows($sql) == 0) { echo 'No resources found.<br>'; } else { while ($c = mysql_fetch_array($sql)) { $device = mysql_query('SELECT deviceName FROM devices WHERE deviceID = "'.mysql_real_escape_string($c["device"]).'"'); $device = mysql_fetch_array($device); echo "{ 'id': '".$c[id]."', \"name\":\"".$device[deviceName]." ".$c[name]."\" },"; } } ?> ]}, proxy: { type: 'memory', reader: { type: 'json', root: 'items' } } });
and the data store is used for my grid:
{ id: 'testernavpanel', title: 'Available Roms', items: [{ xtype: 'grid', title: '', id: 'romGrid', store: Ext.data.StoreManager.lookup('romStore'), columns: [ { header: 'ID', dataIndex: 'id', hidden: true, hideable: false}, { header: 'Name', dataIndex: 'name', width: 240 } ], width: 250, renderTo: Ext.getCmp('testernavpanel'), }], iconCls: 'info' }
Now i have a refresh button. The task of this button is to delete all values in the store and load them new from another php file using ajax:
Ext.Ajax.request({ url: 'expand.php?view=testers_new', method: 'GET', callback: function(options, success, response) { var data = response.responseText; a.getStore().removeAll(); a.getStore().add(data); console.log(data); } });
The new data come from this php code:
$sql = mysql_query('SELECT id, name, device FROM content WHERE access = "1"'); if (mysql_num_rows($sql) == 0) { echo 'No resources found.<br>'; } else { while ($c = mysql_fetch_array($sql)) { $device = mysql_query('SELECT deviceName FROM devices WHERE deviceID = "'.mysql_real_escape_string($c["device"]).'"'); $device = mysql_fetch_array($device); echo "{id: '".$c[id]."', name: '".$device[deviceName]." ".$c[name]."'}, "; } echo "{id:'', name:\"\"}"; }
Now the big problem is, that after i clicked on refresh, all values will be removed, ok. But then only one empty value is added.
The json encoded data is correct transmitted from the php file, i have copied the data from the console and added them to the "a.getStore().add(data);" instead of "data". Then all is ok, and the new data is inserted as the new values.
Has anyone of you an idea why the data of the php file inserted in the store?
Thanks for help and if any more code is needed, please ask ;)
Greetings