PDA

View Full Version : Associations and XTemplates



abheek
25 Jan 2011, 10:00 AM
I noticed a few threads on this forum posing similar questions, but no answers yet. So here's another shot at this.

I have two models, Show hasMany Program, and Program belongsTo Show. I wish to render them in two different lists such that each list has some properties of both elements, and am facing problems with rendering using XTemplates.


Ext.regModel("Program", {
fields: [
{name: "id", type: "int"},
{name: "show_id", type: "int"},
],
associations: [
{type: "belongsTo", model: "Show", name: "show"},
],
proxy: {
type: "ajax",
url: "/a/json/programs",
reader: {
type: "json",
root: "current_programs"
}
}
});

Ext.regModel("Show", {
fields: [
{name: "name", type: "string"},
{name: "id", type: "int"},
],
associations: [
{type: "hasMany", model: "Program", name: "programs"},
],
proxy: {
type: "ajax",
url: "/a/json/shows",
reader: {
type: "json",
root: "all_shows"
}
},
});

At app startup time, I load all the date by calling store.load for both the Show store and the Program store. The List I am trying to use is the following (simplified, and for the Program list.):



var program_list = new Ext.List({
scroll: "vertical",
disableSelection: true,
store: new Ext.data.Store({
model: "Program",
autoLoad: false,
}),
itemTpl: new Ext.XTemplate(
'<tpl for=".">',
'<div class="program-id">{id}</div>',
'<div class="show-title">{show.name}</div>',
'</tpl>'
),
});


However, the show field of the Program object does not seem to be available, and is omitted in the rendered HTML.

Is there another prescribed way to render data with associations using XTemplates? What am i missing here?

Thanks in advance.