I've done a lot of searching for answers and testing, but just can't seem to get the TreePanel in my main view to display the JSON tree data I am getting. I'm hoping someone can call out something I'm doing wrong or not utilizing correctly.
Here is my code:
Tree.json
{
"message": "SUCCESS",
"details": {
"text": "Categories",
"expanded": "true",
"leaf": "false",
"children": [
{
"text": "Child 1",
"leaf": "true"
},
{
"text": "Child 2",
"leaf": "true"
},
{
"text": "Child 3",
"expanded": "true",
"leaf": "false",
"children": [
{
"text": "Grandchild",
"leaf": "true"
}
]
}
]
}
}
Model.js
Ext.define('MyApp.model.Model',{
extend: 'Ext.data.TreeModel',
requires: ['Ext.data.Field'],
fields:['text']
});
Models.js
Ext.define('MyApp.store.Models',{
extend: 'Ext.data.TreeStore',
alias: 'store.models',
model: 'MyApp.model.Model',
autoLoad: true,
proxy: {
type: 'ajax',
url: 'data/Tree.json',
reader: {
type: 'json',
rootProperty: 'details'
}
});
View.js (Snippet)
xtype: 'treepanel',
maxWidth: 300,
minWidth: 150,
store: {
type: 'models',
},
rootVisible: false
In my view, I see an empty tree. When I set rootProperty to 'details', Network tab in Chrome's Developer Tools and Firebug show infinite requesting of my json, but no loading into the view.
Anything to point me in the right direction would be extremely helpful! I can't think of anything I'm doing wrong as the syntax all seems to be correct, so I've hit a dead end.
Thanks!
Edit: I was able to load the json data when creating a store in-line in my view, but not from a separate store.js file. I also changed the store initialization like so:
store: Ext.create('Ext.data.TreeStore',{
fields:['name', 'description'],
proxy: {
type: 'ajax',
url: 'data/Categories.json',
reader: {
type: 'json',
rootProperty: 'children'
}
},
}
I also changed my json's field from "details" to "children", and it was able to display. This likely won't match up with my requirements later, but I'll take what I can get right now (a different JSON format than what I'd like and inline store creation).
Any further help on this would be appreciated!