I am trying to parse the following xml (after hosting in my local machine) and load it to store.
<?xml version="1.0" encoding="UTF-8"?>
<users>
<user>
<id>2</id>
<name>shameel</name>
<post>
<user_id>5</user_id>
<title>programmer</title>
<body>nothing</body>
</post>
<post>
<user_id>6</user_id>
<title>newpost</title>
<body>congrats</body>
</post>
</user>
<user>
<id>3</id>
<name>abdulls</name>
<post>
<user_id>5</user_id>
<title>programmer1</title>
<body>nothing1</body>
</post>
<post>
<user_id>6</user_id>
<title>newpost1</title>
<body>congrats1</body>
</post>
<post>
<user_id>7</user_id>
<title>newpost1</title>
<body>congrats1</body>
</post>
</user>
</users>
The models used are as follows:
Ext.define("SectionModel", {
extend : 'Ext.data.Model',
config : {
fields : [{
name : 'section',
type : 'string',
mapping : '@section'
}],
proxy : {
type : 'ajax',
url : 'http://localhost:8080/sample1.xml', //sample1.xml is the file
reader : {
type : 'xml',
rootProperty : 'configs',
record : 'navigation'
}
},
hasMany : [{
model : 'ArticlesModel',
name : 'articlesModel',
associationKey:'sections'
}]
}
});
Ext.define("ArticlesModel", {
extend : 'Ext.data.Model',
config : {
fields : [{
name : 'title',
type : 'string',
mapping : '@title'
}, {
name : 'value',
type : 'string',
mapping : '@value'
}],
proxy : {
type : 'ajax',
url : 'http://localhost:8080/sample1.xml', //sample1.xml is the file
reader : {
type : 'xml',
rootProperty : 'navigation',
record : 'section'
}
},
belongsTo : 'SectionModel'
}
});
Store used as below:
Ext.define("SectionStore", {
extend : 'Ext.data.Store',
config : {
model : 'SectionModel',
autoLoad : 'true'
}
});
I try to access the content as below:
var store = Ext.data.StoreManager.get('SectionStore');
if (!store) {
console.log("Store not found");
return;
}
store.load(function(records, operation, success) {
for (var i = 0; i < store.getCount(); i++) {
var section_title = store.getAt(i).get('section');
var subsection_val = store.getAt(i).articlesModel().get('title');//this function fails saying no "get" function for the object
}
});
Here I am able to obtain section_title. But cannot get subsection_val. I ve tried this with the proxy in store, but could not fix it. Can any one please help.
See Question&Answers more detail:
os