PDA

View Full Version : accessing a row from a data store



dlstrawn
07-14-2010, 08:12 AM
Is there a way to access a "row" from a 3 row jsonstore based on a value selected in a combo box (without doing a round trip to the server and retrieving the needed record from a file)?

sean.lanktree
07-14-2010, 07:55 PM
Yes - if the JsonStore is linked to the combo box in question then add the "select" listener on the combobox.



listeners: {
select: function(cb, record){ do something....}
}

The second parameter is the record in the JsonStore.

If you want to pull a record from a JsonStore that is not linked to your combo box....


var index = myStore.find('FIELDNAMEINMYSTORE', Ext.getCmp('myCombo').getValue());

var record = myStore.getAt(index);

dlstrawn
07-15-2010, 11:51 AM
OK. I did the following:



listeners: {
'select': function () {
Ext.getCmp('centerP').show();
Ext.getCmp('EmployeeGrid').getStore().reload();
Ext.getCmp('plantPic').html = '<img src="/vvresources/' + this.getRawValue() + 'Plant.jpg" width="100%" height="100%"></img>';
Ext.getCmp('plantPic').body.update('<img src="/vvresources/' + this.getRawValue() + 'Plant.jpg" width="100%" height="100%"></img>');
var esIndex = Plants.find("PLANTNUM", this.getValue());
var esRecord = Plants.getAt(esIndex);
Ext.getCmp('PlantName').setValue(esRecord.data.PLA NTNAM);
}


But it does not work. Am I setting the value (i.e. the value in the box of the textfield, not the fieldLabel) on the textfield with the last statement correct syntactically? Am I refering to the store field name with correct syntax?...

richard.milone
07-16-2010, 09:52 AM
It's difficult for us to tell what might be wrong without being able to debug it directly. Do you have Firebug? If you do and you know how to use it I think you'll have a much easier time coding things where you're not totally sure of the syntax. For example, if you insert some console logging lines you can then inspect the entries in the console and see the values at these points. You can even inspect the structure of complex objects to derive syntax.


var esIndex = Plants.find("PLANTNUM", this.getValue());
console.log(Plants);
console.log(esIndex);
var esRecord = Plants.getAt(esIndex);
console.log(esRecord);
Ext.getCmp('PlantName').setValue(esRecord.data.PLA NTNAM);

You could also try the Script tab and set breakpoints in the code to see what's going on.

dlstrawn
07-16-2010, 10:00 AM
I have set breakpoints (with a watch) in firebug to see the values in question. esRecord and esIndex are correct. The problem is the .setValue(esRecord.data.PLANTNAM) is not actually "modifying" the targeted component (a textField in a form, that has already been rendered) I even tried this:


Ext.getCmp('PlantName').setValue('test value 2')


But to no avail. I think my issue is the "state" of the targeted component (already rendered, just hidden), any suggestions?