PDA

View Full Version : XML Attributes in Combo Boxes



ismoore
3 Aug 2007, 10:54 AM
I have been creating a combo box that reads back XML from the server whereby the field to be displayed within the combo box is actually an attribute of the record



Bijective.Operations.dsZBAccount = new Ext.data.Store({
// load using HTTP
proxy: new Ext.data.HttpProxy({url:Bijective.constants.mvc+"/accountManager"}),
baseParams: {action:"list"},
// the return will be XML, so lets set up a reader
reader: new Ext.data.XmlReader({
record: 'account',
id: '@cashpoolname'
}, ["@accountname", "@currency", "@zerobalance", "@mintransfer", "@state"])
})

var combo = new Ext.form.ComboBox({
boxLabel:"account",
store: Bijective.Operations.dsZBAccount,
displayField:'@accountname',
typeAhead: true,
mode: 'remote',
triggerAction: 'all',
emptyText:'Select an account...',
selectOnFocus:true,
width:135,
forceSelection:true,
minChars:2,
tooltip: {text:'Select the account to be balanced', title:'Master Account', autoHide:true}

});


The problem that I have is that the values within the combo dropdown are displayed as {@accountname} (and there is also only one of them irrespective of how many records I assume to be produced).
I know the values are being returned correctly as once an accountname is known the typeahead functionality populates the entire box with the correct account.

Looking though the code my guess is that the template expansion of {@accountname} does not seem to be substituting the value correctly from what I can see in the XML though that does not fully answer why there is only one record displayed when multiple are returned

I have no problems with other combo boxes taking in items - this is the only one that uses an XML attribute.

Sample XML


<cashpool>
<account accountname="9879876" cashpoolname="null" currency="null" zerobal="null" mintransfer="null" state="1" />
<account accountname="7685490" cashpoolname="null" currency="null" zerobal="null" mintransfer="null" state="1" />
<account accountname="1222333" cashpoolname="null" currency="null" zerobal="null" mintransfer="null" state="1" />
<account accountname="2556667" cashpoolname="null" currency="null" zerobal="null" mintransfer="null" state="1" />
<account accountname="3928273" cashpoolname="null" currency="null" zerobal="null" mintransfer="null" state="1" />
</cashpool>


Some data has been edited to protect the innocent!

I think this is a bug unless I am doing something really stupid!
Ian

jack.slocum
3 Aug 2007, 11:01 AM
Please take a look at the docs for how to define a Record type. The XML Grid example will also give you an idea of the way to set up a store to read XML data.

In particular, you need to define a name and a mapping. The mapping will contain the XPath @account but the name will need to be a normal name (e.g. account).

ismoore
3 Aug 2007, 11:28 AM
sorry I should have known that - have even done it before.
It's Friday - It has been a long week.

Ian