PDA

View Full Version : passing data and how to access it correctly



groophug
10 Oct 2012, 11:29 PM
Hello all, any help for a nubee greatly appreciated.

I am passing data successfully to a view via the following code:



...
itemtap: function (list, index, target, record) {
...
Ext.Viewport.animateActiveItem (
{xtype: 'page_videoplayer', data: record.data},
{type:'pop'}
);
}



I am able to access that data partially in a tpl using the initialize function, however i would like to access that data inside of the 'video' xtype as well in order to set the 'url' and 'posterUrl' correctly. See the commented sections for where i am accessing the data that was passed to the following panel:






Ext.define('myapp.view.panel_VideoPlayer', {
extend: 'Ext.Panel',
xtype: 'page_videoplayer',

requires: [
'Ext.Video'
],
// I CAN APPLY THE DATA SUCCESSFULLY TO TPL BELOW USING THIS FUNCTION
initialize:function (){
var panels = this.query('panel[tpl]'),
pLen = panels.length,
p = 0,
panel;
for (p=0; p < pLen; p++) {
panel = panels[p];
panel.setData(this.getData());
}
},

layout: {
type: 'vbox'
},

config: {
title: 'VideoPlayer',
cls: 'bluePanel',
scrollable: true,
styleHtmlContent: true,

items: [
{
items:[
{
xtype: 'video',
itemId: 'vplayer',
title: 'video player',
width: '100%',
height: 200,
listeners: {
activate: function(){
// HOW WOULD I CORRECTLY ACCESS THE DATA HERE? THIS OBVIOUSLY NOT CORRECT
this.setUrl('http://myurl/'+record.getData('videofile'));
this.setPosterUrl('http://myurl/'+record.getData('videothumb'));
}
}
}
]
},
{
xtype:'panel',
tpl:[
// VIA THE INITIALIZE FUNCTION ABOVE I AM ABLE TO ACCESS THE DATA SUCCESSFULLY HERE
'Title: {videotitle}</br>',
'User: {username}</br>',
'Rating: {videorating}</br>',
'Views: {videoviews}',
'',
''
].join(''),
flex:1
}
]
}
});

SebasSP
11 Oct 2012, 4:00 AM
this.up('page_videoplayer').getData()

groophug
11 Oct 2012, 6:26 AM
SebasSP — sincere thanks for your reply — can you show me exactly how you would apply this?

I tried your suggestion as follows:


xtype: 'video',
itemId: 'vplayer',
title: 'video player',
width: '100%',
height: 200,
enableControls: true,
listeners: {
activate: function(){
var videoFile = this.up('page_videoplayer').getData('videofile');
this.setUrl('http://myurl.com/'+videoFile+'.m4v');
this.setPosterUrl('http://myurl.com/'+videoFile+'png');
}


but i get the following error in the console:
TypeError: 'undefined' is not an object (evaluating 'this.up('page_videoplayer').getData')