javascript-如何定义将组件添加到DataItem的顺序
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了javascript-如何定义将组件添加到DataItem的顺序,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2848字,纯文字阅读大概需要5分钟。
内容图文
![javascript-如何定义将组件添加到DataItem的顺序](/upload/InfoBanner/zyjiaocheng/657/755e15a0eea9459cbf6bcc65c564cd95.jpg)
我已经阅读了tutorial,其中涉及为Store中的每个元素创建具有自定义组件的DataView.它谈到了将记录字段映射到DataItem中的组件,但是我的问题是如何定义将组件添加到DataItem中的顺序.
例如,我有这样的DataItem:
Ext.define('demo.view.CottageItem', {
extend: 'Ext.dataview.component.DataItem',
requires: ['Ext.Label', 'Ext.Array', 'Ext.Img'],
xtype: 'listitem',
config: {
layout: {
type: 'hbox',
align: 'center',
pack: 'start',
},
title: {
flex: 1
},
photo: {
width: '140px',
height: '140px'
},
dataMap: {
getTitle: {
setHtml: 'title'
},
getPhoto: {
setSrc: 'photo'
}
},
styleHtmlContent: true
},
applyTitle: function(config) {
return Ext.factory(config, Ext.Label, this.getTitle());
},
updateTitle: function(newTitle, oldTitle) {
if (oldTitle) {
this.remove(oldTitle);
}
if (newTitle) {
this.add(newTitle);
}
},
applyPhoto: function(config) {
return Ext.factory(config, Ext.Img, this.getPhoto());
},
updatePhoto: function(newImage, oldImage) {
if (oldImage) {
this.remove(oldImage);
}
if (newImage) {
this.add(newImage);
}
},
});
它的布局类型为hbox,因此我希望先添加照片,然后再添加标题.这样标题就在照片的右边.我该如何实现?
另一个问题是,是否有办法在此DataItem中添加另一个容器,可以在其中插入我的Label和Image?
更新:
现在我的布局看起来像这样:
|标签(标题)| |图片(照片)|
我希望它看起来像这样:
|图片(照片)| |标签(标题)|
解决方法:
最后,我了解了如何解决我的问题,这是我的代码:
Ext.define('demo.view.CottageItem', {
extend: 'Ext.dataview.component.DataItem',
requires: ['Ext.Label', 'Ext.Array', 'Ext.Img'],
xtype: 'listitem',
config: {
layout: {
type: 'hbox',
align: 'center',
pack: 'start',
},
title: {
style: {
'font-weight': 'bold'
}
},
photo: {
width: '140px',
height: '140px'
},
desc: {},
dataMap: {
getTitle: {
setHtml: 'title'
},
getPhoto: {
setSrc: 'photo'
},
getDesc: {
setHtml: 'desc'
},
},
styleHtmlContent: true,
items: [
{
xtype: 'panel',
itemId: 'photoContainer',
},
{
xtype: 'panel',
layout: {
type: 'vbox'
},
itemId: 'textContainer',
flex: 1,
}
],
},
applyTitle: function(config) {
return Ext.factory(config, Ext.Label, this.getTitle());
},
updateTitle: function(newTitle, oldTitle) {
if (oldTitle) {
this.getComponent('textContainer').remove(oldTitle);
}
if (newTitle) {
this.getComponent('textContainer').add(newTitle);
}
},
applyPhoto: function(config) {
return Ext.factory(config, Ext.Img, this.getPhoto());
},
updatePhoto: function(newImage, oldImage) {
if (oldImage) {
this.getComponent('photoContainer').remove(oldImage);
}
if (newImage) {
this.getComponent('photoContainer').add(newImage);
}
},
applyDesc: function(config) {
return Ext.factory(config, Ext.Label, this.getDesc());
},
updateDesc: function(newDesc, oldDesc) {
if (oldDesc) {
this.getComponent('textContainer').remove(oldDesc);
}
if (newDesc) {
this.getComponent('textContainer').add(newDesc);
}
},
});
我没有在根目录中添加组件,而是在DataItem中定义了两个面板(占位符).我使用getComponent方法访问它们,并将我的组件添加到所需的位置.唯一的问题是,添加到textContainer的项目顺序是不确定的,但是在我的情况下,我得到了所需的顺序.
内容总结
以上是互联网集市为您收集整理的javascript-如何定义将组件添加到DataItem的顺序全部内容,希望文章能够帮你解决javascript-如何定义将组件添加到DataItem的顺序所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。