2012-05-14 84 views
0

我想知道是否有可能包含数据并在Sencha Touch 2中的模板中创建一个新的对象?Sencha触摸2面板带模板包括数据和对象

我有以下代码:

Ext.define('MyApp.view.VideosDetail', { 
extend: 'Ext.Panel', 
xtype: 'videosdetail', 

config: { 
    title: 'Details', 
    styleHtmlContent: true, 
    scrollable: 'vertical', 
    tpl: [ 
     '{content}', 
     { 
      xtype: 'video', 
      width: 400, 
      height: 400, 
      url: '{link}' 
     } 
    ] 
} 
}); 

我看到[object Object],而不是与URL链接的视频对象。

{content}通过商店等正常工作。

回答

0

好吧,两件事情你必须记住

  1. 你只是做的方式,您不能使用第三方物流的内部复杂的对象。在Sencha Touch中,在tpl字符串后面添加“,”后跟“{。。}”意味着将成员函数或配置添加到XTemplate。在这种情况下,ST误解你的对象是类的成员函数,并没有显示任何东西,因为你没有调用任何函数。

的成员函数实例::

var tpl = new Ext.XTemplate(
'<p>Name: {name}</p>', 
'<p>Kids: ', 
'<tpl for="kids">', 
    '<tpl if="this.isGirl(name)">', 
     '<p>Girl: {name} - {age}</p>', 
    '<tpl else>', 
     '<p>Boy: {name} - {age}</p>', 
    '</tpl>', 
    '<tpl if="this.isBaby(age)">', 
     '<p>{name} is a baby!</p>', 
    '</tpl>', 
'</tpl></p>', 
{ 
    // XTemplate configuration: 
    disableFormats: true, 
    // member functions: 
    isGirl: function(name){ 
     return name == 'Sara Grace'; 
    }, 
    isBaby: function(age){ 
     return age < 1; 
    } 
} 
); 
  • 如果有一个复杂的对象TPL,总是试图创建一个单独的XTemplate对象,而不是,这将使你的代码简单而美观(即易于阅读)

  • 我已经做了类似的事情,并将视频添加到我的XTemplate之前。但我没有使用视频对象。相反,我的TPL我创建看起来如下::

    Sorry I couldnt paste in the code, but StackOverflow was assuming it was html, and actually showing me the tpl output instead :P

  • 我的方案,我的视频的网址是由两个部分组成,vurl1是共同的东西,如“www.youtube.com /看?”而vcode1是随后的动态代码。