PDA

View Full Version : Problem with ComboBox and XML



johnvp
6 Jun 2010, 3:53 AM
I can't load data from local XML-file to Combobox

My data.xml


<?xml version="1.0" encoding="UTF-8"?>
<rows>
<row>
<id>1</id>
<name>User1</name>
</row>
<row>
<id>1</id>
<name>User2</name>
</row>

</rows>


my HTML


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="./ext/resources/css/ext-all.css" />

<title>Insert title here</title>
<script type="text/javascript" src="./ext/adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="./ext/ext-all-debug.js"></script>
<script language=JavaScript src=new.js > </script>
</head>
<body>
<input type= button id="show-button" value="Window" >

</body>
</html>


and my new.js


Ext.onReady(
function() {
var button=Ext.get('show-button');
var win;
var mystore=new Ext.data.Store({
url:'data.xml',
autoLoad:true,
reader: new Ext.data.XmlReader({
record:'row',
id:'id',
},
['id','name']
)
});
var combo=new Ext.form.ComboBox({
forceSelection: true,
triggerAction: 'all',
selectOnFocus:true,
lazyInit: false,
displayField:'name',
store: mystore,
fieldLabel:'User'
});
var form = new Ext.form.FormPanel({
baseCls: 'x-plain',
layout:'form',
id:'form1',
items:[
combo,
{
id:'pass',
xtype:'textfield',
inputType: 'password',
fieldLabel:'Password'
}
]
});
button.on('click',function(){
if (!win) {
win = new Ext.Window({

layout:'fit',
width:500,
height:300,
closeAction:'hide',
plain: true,
items: form,
});
};
win.show(this);
});
});



Please, help me.

P.S. Sorry, for my bad English.

gevik
6 Jun 2010, 4:35 AM
Humm... your code looks fine. Wat is the error that your get in FireBug?

Animal
6 Jun 2010, 6:52 AM
That's not valid HTML though is it? I mean YOUR script tag compared to the copy/pasted code!

Also, use idProperty in your Reader definition as per the docs as opposed to copy/pasting outdated code from somewhere.

Also, WHAT exactly is your problem? Is the Stored loaded? You can look at it to find out!

johnvp
6 Jun 2010, 7:04 AM
I dont have any error in FireBug. ComboBox opened empty.

johnvp
6 Jun 2010, 7:13 AM
Stored didn't load any data from xml, and combobox is empty. I don't understand why it's hapened.

gevik
6 Jun 2010, 7:30 AM
I tested your code by putting it on a webserver.

There is a little error in the xml. Both IDs are "1". I changed this to "1" and "2"
I also changed the location of ext file according to my server configuration.
Look at the attached image.
Perhaps this helps,

johnvp
6 Jun 2010, 9:47 AM
When I run this under apache server it's worked!!!
Thank you for help!