Я прочитал много вопросов / ответов и учебных пособий, и мне все еще не удается реализовать иерархическую модель в Sencha Touch.Корневой моделью является Tag.Каждый тег имеет много предметов.Вот моя модель:
Корневой тег:
app.models.Tag = Ext.regModel("Tag", {
fields : [ {
name : "id",
type : "int"
}, {
name : "name",
type : "string"
}],
associations : {
type : "hasMany",
model : "TagItem",
name : "items"
}
});
Adjected TagItem
app.models.TagItem = Ext.regModel("TagItem", {
fields : [ {
name : "id",
type : "int"
}, {
name : "title",
type : "string"
}, {
name : "type",
type : "string"
}, {
name : "tag_id",
type : "int"
}],
associations : {
belongsTo : {
model : "Tag",
name : "items"
}
}
});
TagStore:
app.stores.tagItems = new Ext.data.Store({
model : "app.models.TagItem",
proxy : {
type : 'scripttag',
root : 'items',
url : 'http://www.s-lab.cz/ios/api/tags.php'
}
});
Теги:
app.stores.tags = new Ext.data.Store({
model : "app.models.TagItems",
proxy : {
type : 'scripttag',
url : 'http://www.s-lab.cz/ios/api/tags.php'
}
});
Когда я пытаюсь загрузить элементы из магазина, я получаю:
Uncaught TypeError: Невозможно вызвать метод 'read' из неопределенного
My JSONвыглядит так:
stcCallback1005([
{
"id":1,
"name":"Doktor",
"url":"doktor",
"items":[
{
"type":"video",
"id":1,
"title":"First tag item",
"tag_id":1
},
{
"type":"article",
"id":1,
"title":"Second tag item - article",
"tag_id":1
},
{
"type":"article",
"id":2,
"title":"Third tag item - article",
"tag_id":1
},
{
"type":"video",
"id":2,
"title":"Fourth tag item",
"tag_id":1
}
]
},
{
"id":2,
"name":"Nemocnice",
"url":"nemocnice"
},
{
"id":3,
"name":"Sestra",
"url":"sestra"
}
]);
Обновление:
Я изменил код с предложениями, и в результате JSON выглядит так:
stcCallback1005({
"results": [{
"id": 1,
"name": "Doktor",
"url": "doktor",
"items": [{
"type": "video",
"id": 1,
"title": "First tag item",
"tag_id": 1
}, {
"type": "article",
"id": 1,
"title": "Second tag item - article",
"tag_id": 1
}, {
"type": "article",
"id": 2,
"title": "Third tag item - article",
"tag_id": 1
}, {
"type": "video",
"id": 2,
"title": "Fourth tag item",
"tag_id": 1
}]
}, {
"id": 2,
"name": "Nemocnice",
"url": "nemocnice"
}, {
"id": 3,
"name": "Sestra",
"url": "sestra"
}]
});
Но все же я не могу получить доступ к последующим элементам: app.stores.tags.getAt(0)
работает, а app.stores.tags.getAt(0).TagItems()
- нет (ни app.stores.tags.getAt(0).items
, ни app.stores.tags.getAt(0).items()
не работает).А также мой шаблон не отображается правильно: <tpl for=".">{name}<ul><tpl for="items"><li>{title} ({type})</li></tpl></ul></tpl>
Есть идеи?