开发者

Data within Ext.Panel without XTemplate?

开发者 https://www.devze.com 2023-04-10 16:58 出处:网络
is there a way to apply data to \"regular\" fields and subitems without using the an XTemplate? My code looks like:

is there a way to apply data to "regular" fields and subitems without using the an XTemplate?

My code looks like:

var panel = new Ext.Panel({
   data: myDataBlock
   defaults: {
      data: myDataBlock
   }
   title: 'Name: {name}'
   items: [{
       xtype: 'panel',
       title: 'more: {moreData}'
   }]
});

What would be required to have proper substitudes with the data form "myDat开发者_StackOverflow中文版aBlock" ?

Cheers


What do you mean by "regular" fields?

The data property of Panel is the initial data you want rendered, and it gets rendered using a template. You can specify a custom template for rendering if you wish, but either way it has to use a template so that ExtJS knows how to render your content.

Look at the source code for Component:

if (this.data) {
    this.tpl[this.tplWriteMode](contentTarget, this.data);
    delete this.data;
}

data: The initial set of data to apply to the tpl to update the content area of the Component.


If I understand correctly, you want to create the panel dynamically by a data block to set the properties like title etc...

If so, my suggestion is write your own panel class that extends Ext.Panel and do the things before its components is initiated.

Sample:

//Define your own panel class
MyPanel = Ext.extend(Ext.Panel, {
  width: 300,
  height: 150,
  initComponent: function(){
     if(this.data){
        Ext.apply(this,{
           title: 'Name: '+ this.data.title,
           items: [
              {
                 xtype: 'panel',
                 html: 'more: '+ this.data.moreData
              }
           ]
        });
     }
     MyPanel.superclass.initComponent.call(this);
  }
});

//Use the customized panel
var p = new MyPanel({
   data: {title:'my title', moreData: 'other data'},
   renderTo: Ext.getBody()
});

By the way, Template is only used to render the content of a panel in a plain way. In your case it's not proper to use Template because it has nothing to do with the config property nor the items of a panel.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号