Я пытаюсь разобрать следующий xml (после размещения на моей локальной машине) и загрузить его для хранения.Чтение вложенных XML-моделей с помощью ассоциации hasMany, Sencha, ExtJS
<?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>
Модели, используемые в следующем:
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'
}
});
магазин используется, как показано ниже:
Ext.define("SectionStore", {
extend : 'Ext.data.Store',
config : {
model : 'SectionModel',
autoLoad : 'true'
}
});
Я пытаюсь получить доступ к контенту, как показано ниже:
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
}
});
Здесь Я могу получить section_title. Но не может получить subsection_val. Я пробовал это с прокси-сервером в магазине, но не смог его исправить. Может ли кто-нибудь помочь.
Да JSON является вариант. XML некоторые из них создают проблемы. Мы инкапсулировали XML в jsonp и получили его. – buddy