PDA

View Full Version : Can't get nested model in data store



bbonnet
14 Apr 2011, 7:29 AM
Hi, I've been working with Sencha for a few weeks now and I really enjoy working with the framework. However, I'm having trouble accessing a nested model within my data store. I'm using a json data source and manually populating it because the initial stage of my project is a demo and doesn't yet have a database set up. My store is called newJSONStore and it's model property is 'CourseItem'. The CourseItem model contains several properties (id, title, module, unit, page) and a nested model called 'ContentItem'. I can get all the properties of the CourseItem model, but for some reason when I debug this, I can't get the 'ContentItem' model to show up as a property in the debugger. I tried the same exercise with the kitchensink demo's nested data loading example and I was able to see the nested model showing up as a property of the data object in the debugger. So my question is, what's preventing me from seeing my nested model? I think I created everything according to the documentation, so I need help understanding what I need to do differently. Is the problem with my json or with my sencha code?
My code is below:

here's an example of one of my json code objects, there are several of them, in the content.json file, and all look like this:



{
"id": 1,
"title":"first Screen",
"module":1,
"unit":1,
"page":1,
contentItems":[
{
"contentID":"htmlText",
"content":"this is the first content screen text"

},
{
"contentID":"graphic",
"content":"pic.jpg"
}


]


}



Here's my Sencha code. You can see that I have a callback to handleJsonLoad2 and that's where I set a breakpoint in the debugger to view the objects returned from the load. I can see id, title, module, unit, page, but I should also see contentItems and I can't see it.



var handleJsonLoad2 = function(s,a,t){
var teststring = 'hello';
}



Ext.regModel('CourseItem',{

fields: [{name:'id',type:'int'},{name:'title',type:'string'},{name:'module',type:'int'},{name:'unit',type:'int'},{name:'page',type:'int'}],
hasMany: {model: 'ContentItem', name: 'contentItems'},

proxy: {
type: 'ajax',
url : 'data/content.json'
}

});

Ext.regModel('ContentItem',{
fields: [{name:'contentID',type:'string'},{name:'content',type:'string'}]
});



var newJSONStore = new Ext.data.Store({
model:'CourseItem',
storeId: 'courseStore',
autoLoad: true,
listeners: {
load: handleJsonLoad2
}
})



Any help you can provide will be great. Thanks in advance.