]>
git.proxmox.com Git - sencha-touch.git/blob - src/src/dataview/component/ListItem.js
2 * A ListItem is a container for {@link Ext.dataview.List} with
3 * useSimpleItems: false.
5 * ListItem configures and updates the {@link Ext.data.Model records} for
6 * the sub-component items in a list.
8 * Overwrite the `updateRecord()` method to set a sub-component's value.
9 * Sencha Touch calls `updateRecord()` whenever the data in the list updates.
11 * The `updatedata` event fires after `updateRecord()` runs.
13 * *Note*: Use of ListItem increases overhead since it generates more markup than
14 * using the List class with useSimpleItems: true. This overhead is more
15 * noticeable in Internet Explorer. If at all possible, use
16 * {@link Ext.dataview.component.SimpleListItem} instead.
18 * The following example shows how to configure and update sub-component items
21 * Ext.define('Twitter.view.TweetListItem', {
22 * extend: 'Ext.dataview.component.ListItem',
23 * xtype : 'tweetlistitem',
46 * applyUserName: function(config) {
47 * return Ext.factory(config, Ext.Component, this.getUserName());
50 * updateUserName: function(newUserName) {
52 * this.insert(0, newUserName);
56 * applyText: function(config) {
57 * return Ext.factory(config, Twitter.view.TweetListItemText, this.getText());
60 * updateText: function(newText) {
66 * applyAvatar: function(config) {
67 * return Ext.factory(config, Ext.Img, this.getAvatar());
70 * updateAvatar: function(newAvatar) {
72 * this.add(newAvatar);
76 * updateRecord: function(record) {
81 * this.getUserName().setHtml(record.get('username'));
82 * this.getText().setHtml(record.get('text'));
83 * this.getAvatar().setSrc(record.get('avatar_url'));
84 * this.callParent(arguments);
90 Ext
.define('Ext.dataview.component.ListItem', {
91 extend
: 'Ext.dataview.component.DataItem',
95 baseCls
: Ext
.baseCSSPrefix
+ 'list-item',
101 cls
: 'x-list-item-body'
106 cls
: 'x-list-disclosure',
113 cls
: 'x-list-header',
121 applyBody: function(body
) {
122 if (body
&& !body
.isComponent
) {
123 body
= Ext
.factory(body
, Ext
.Component
, this.getBody());
128 updateBody: function(body
, oldBody
) {
131 } else if (oldBody
) {
136 applyHeader: function(header
) {
137 if (header
&& !header
.isComponent
) {
138 header
= Ext
.factory(header
, Ext
.Component
, this.getHeader());
143 updateHeader: function(header
, oldHeader
) {
149 applyDisclosure: function(disclosure
) {
150 if (disclosure
&& !disclosure
.isComponent
) {
151 disclosure
= Ext
.factory(disclosure
, Ext
.Component
, this.getDisclosure());
156 updateDisclosure: function(disclosure
, oldDisclosure
) {
158 this.add(disclosure
);
159 } else if (oldDisclosure
) {
160 oldDisclosure
.destroy();
164 updateTpl: function(tpl
) {
165 this.getBody().setTpl(tpl
);
168 updateRecord: function(record
) {
170 dataview
= me
.dataview
|| this.getDataview(),
171 data
= record
&& dataview
.prepareData(record
.getData(true), dataview
.getStore().indexOf(record
), record
),
172 dataMap
= me
.getDataMap(),
173 body
= this.getBody(),
174 disclosure
= this.getDisclosure();
179 me
.doMapData(dataMap
, data
, body
);
181 body
.updateData(data
|| null);
184 if (disclosure
&& record
&& dataview
.getOnItemDisclosure()) {
185 var disclosureProperty
= dataview
.getDisclosureProperty();
186 disclosure
[(data
.hasOwnProperty(disclosureProperty
) && data
[disclosureProperty
] === false) ? 'hide' : 'show']();
191 * Fires whenever the data of the DataItem is updated.
192 * @param {Ext.dataview.component.DataItem} this The DataItem instance.
193 * @param {Object} newData The new data.
195 me
.fireEvent('updatedata', me
, data
);
198 destroy: function() {
199 Ext
.destroy(this.getHeader());
200 this.callParent(arguments
);