[英]Sencha touch 2 list inside a panel
我需要一个非常常见的任务,我需要一个列表上方的搜索表单来显示结果,问题是列表没有显示结果,存储和代理工作正常,因为当我使用firebug来查找列表项时列表的高度始终为0px。
我已经搜索过,解决这个问题的常用方法是使用适合的布局,但在父面板上使用它会使所有看起来都很小,就像使用的宽度是10px一样。
我不能设置一个固定的高度,因为我希望列表填充剩余的空间,并且当我希望使用按钮和输入字段的默认大小时,flex选项不会导致拉伸搜索表单。
这是我在视图上使用的配置
Ext.define('MyApp.view.search.Search', {
extend:'Ext.navigation.View',
xtype: 'search_view',
config:{
items:[
{
fullscreen:true,
scroll:false,
xtype:'panel',
title:'Search',
items:[
{
xtype:'searchfield',
name:'search',
label:'Search',
},
{
xtype:'container',
layout:'hbox',
width:'100%',
margin:'3 0 0 0',
defaults:{
flex:1
},
items:[
{
xtype:'selectfield',
options:[
{text:'Option 1', value:'opt1'},
{text:'Option 2', value:'opt2'}
]
},
{
xtype:'button',
text:'Search',
action:'search'
}
]
},
{
xtype:'list',
itemTpl:['{title}'],
onItemDisclosure:true,
plugins:[
{ xclass: 'Ext.plugin.ListPaging' }
]
}
]
},
],
}
});
这个图像描述了我想要实现的内容,我通过手动设置高度到列表容器来获取此屏幕截图,因为您可以看到它的工作原理问题是列表高度默认情况下不填充表单下方的空间。
这就是我最终要做的解决这个问题,它更多的是一种解决方法,因为我必须将布局更改为仅包含列表,并使用工具栏作为搜索选项,这样工具栏控件只使用它们的最小高度需要正确地画出自己。
Ext.define('MyApp.view.search.Search', {
extend:'Ext.Container',
xtype: 'search_view',
config:{
fullscreen:true,
layout:'card'
items:[
{
xtype:'toolbar',
docked:'top',
items:[
{
xtype:'searchfield',
name:'search',
flex:6
},
{
xtype:'button',
action:'search',
iconCls:'search',
iconMask:true,
ui:'simple',
flex:1
}
]
},
{
xtype:'toolbar',
docked:'top',
items:[
{
xtype:'selectfield',
flex:1,
options:[
{text:'Option 1', value:'opt1'},
{text:'Option 2', value:'opt2'}
]
}
]
},
{
xtype:'list',
itemTpl:['{title}'],
onItemDisclosure:true,
plugins:[
{ xclass: 'Ext.plugin.ListPaging' }
]
},
],
}
});
如您所见,我有两个工具栏停靠在顶部,列表填充整个布局。 这是它现在看起来的截图。
谢谢你的时间。
你尝试过将容器布局设置为“适合”吗?基本上它会使用所有剩余的可用高度,这里有一个关于sencha touch布局的精彩指南: http : //docs.sencha.com/touch/2-0/从文档中直接#!/ guide / layouts !
面板应具有vbox
布局,列表应具有fit
布局并设置flex
选项。
如果示例如下所示,如果未将flex
值设置为按钮,则应获得默认大小。
从文档 :
弯曲意味着我们根据每个子组件的flex来划分可用区域...
这是一个例子:
Ext.define('MyApp.view.Main',{extend:'Ext.tab.Panel',
config: {
tabBarPosition: 'bottom',
items: [
{
title: 'Welcome',
iconCls: 'home',
html: [
"Some content"
].join("")
},
{
title: "About",
iconCls: 'star',
layout: "vbox", // this card has vbox layout
items: [{
docked: 'top',
xtype: 'titlebar',
title: 'List'
},
{
xtype: "list",
layout: "fit", // take as much space as available
flex: 1, // define flex
data: [
{name: 'Jamie Avins', age: 100},
{name: 'Rob Dougan', age: 21},
{name: 'Tommy Maintz', age: 24},
{name: 'Jacky Nguyen', age: 24},
{name: 'Ed Spencer', age: 26}
],
itemTpl: '{name} is {age} years old'
},
{
xtype: 'button',
text: "Button"
}
]
}
]
}
});
截图:
注意:我正在学习Sencha Touch,所以我不确定写的是否正确。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.