View Full Version : Issue with retrieving data from JsonStore

18 May 2010, 3:22 PM
I have problem with retrieving value of form element.
I am using Ext.data.JsonStore and I am trying to retrieve data using getAt( Number index ) and getById( String id ) method.
But both did not work.
Here is my code. Please help.
Once this is sorted out, I need to remove repeatative code getting values one by one.
Anyway, lets get first problem sorted.

Thanks in advance,

newbug = function(){
var bug_panel = new Ext.Panel({
id: 'new_bug_panel'
var caserun_id;
if (Ext.getCmp('caserun_grid') && Ext.getCmp('caserun_grid').getSelectionModel().getCount()) {
caserun_id = Ext.getCmp('caserun_grid').getSelectionModel().getSelected().get('caserun_id');
var store = new Ext.data.Store({
url: 'tr_process_case.cgi',
baseParams: {
action: 'case_to_bug',
case_id: this.tcid,
caserun_id: caserun_id
reader: new Ext.data.XmlReader({
record: 'newbug',
id: 'case_id'
}, [{
name: 'product',
mapping: 'product'
}, {
name: 'version',
mapping: 'version'
}, {
name: 'component',
mapping: 'component'
}, {
name: 'comment',
mapping: 'comment'
}, {
name: 'case_id',
mapping: 'case_id'
}, {
name: 'assigned_to',
mapping: 'assigned_to'
}, {
name: 'qa_contact',
mapping: 'qa_contact'
}, {
name: 'short_desc',
mapping: 'short_desc'
store.on('load', function(){
var params = '';
var url = 'enter_bug.cgi?';
var form = document.createElement("form");
form.setAttribute("method", 'post');
form.setAttribute("action", url);

var hiddenField1 = document.createElement("input");
hiddenField1.setAttribute("type", "hidden");
hiddenField1.setAttribute("name", 'product');
hiddenField1.setAttribute("value", store.getAt(1));

var hiddenField2 = document.createElement("input");
hiddenField2.setAttribute("type", "hidden");
hiddenField2.setAttribute("name", 'version');
hiddenField2.setAttribute("value", store.getAt(2));

var hiddenField3 = document.createElement("input");
hiddenField3.setAttribute("type", "hidden");
hiddenField3.setAttribute("name", 'component');
hiddenField3.setAttribute("value", store.getAt(3));

var hiddenField4 = document.createElement("input");
hiddenField4.setAttribute("type", "hidden");
hiddenField4.setAttribute("name", 'comment');
hiddenField4.setAttribute("value", store.getAt(4));

var hiddenField5 = document.createElement("input");
hiddenField5.setAttribute("type", "hidden");
hiddenField5.setAttribute("name", 'case_idb');
hiddenField5.setAttribute("value", store.getAt(5));

var hiddenField6 = document.createElement("input");
hiddenField6.setAttribute("type", "hidden");
hiddenField6.setAttribute("name", 'assigned_to');
hiddenField6.setAttribute("value", store.getAt(5));

var hiddenField7 = document.createElement("input");
hiddenField7.setAttribute("type", "hidden");
hiddenField7.setAttribute("name", 'qa_contacts');
hiddenField7.setAttribute("value", store.getAt(6));

var hiddenField8 = document.createElement("input");
hiddenField8.setAttribute("type", "hidden");
hiddenField8.setAttribute("name", 'short_desc');
hiddenField8.setAttribute("value", store.getAt(7));


/* for (var i = 0; i < store.fields.keys.length; i++) {
var str_1 = escape(store.getAt(0).get(store.fields.keys[i]));
//url = url + store.fields.keys[i] + '=' + str_1 + '&';
params = params + store.fields.keys[i] + '=' + str_1 + '&';

//url = url + 'caserun_id=' + caserun_id;
//params = params + 'caserun_id=' + caserun_id;
//alert('url is --> '+url);
//alert('params is --> '+params);
//pass_to_url(url, params, 'POST');
//window.open(url, params, 'POST');

19 May 2010, 1:17 AM
It's really hard to tell what you're doing here - try using CODE tags in future - but, for a start, if you read the docs you'll see that getAt() (http://www.extjs.com/deploy/dev/docs/?class=Ext.data.Store&member=getAt) returns a record not a field value. Try:

store.on('load', function()
var rec = store.getAt(0); // Assuming there is at least 1 record, and you want to access the 1st

// ... I've no idea why you are doing it this way...???

hiddenField1.setAttribute("name", 'product');
hiddenField1.setAttribute("value", rec.data['product']); // rec.get('product') or rec.data.product
// ...

19 May 2010, 3:06 AM
and btw - all of this code is not needed and not the way doing it in ExtJS. Use a FormPanel and bind a store to it, the fields are set automatic if the names match.

19 May 2010, 3:19 AM
The OP doesn't even need a form! A simple Ext.Ajax.request will do!

store.on('load', function(){
var r = store.getAt(0);
method: 'POST',
url: 'enter_bug.cgi',
params: {
product: r.get('product'),
version: r.get('version'),
component: r.get('component'),
comment: r.get('comment'),
case_id: r.get('case_id'),
assigned_to: r.get('assigned_to'),
qa_contact: r.get('qa_contact'),
short_desc: r.get('short_desc')
success: function(response){
// do something
failure: function(response){
// do something else