Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 如何在不使用sencha touch中的ID的情况下获取分段按钮?_Html_Extjs4_Sencha Touch_Sencha Architect_Sencha Touch 2.2 - Fatal编程技术网

Html 如何在不使用sencha touch中的ID的情况下获取分段按钮?

Html 如何在不使用sencha touch中的ID的情况下获取分段按钮?,html,extjs4,sencha-touch,sencha-architect,sencha-touch-2.2,Html,Extjs4,Sencha Touch,Sencha Architect,Sencha Touch 2.2,Ext.getCmp'segmentWidget'.setPressedButtons0 我如何在不使用ID的情况下执行此操作 谢谢如果您不想在Sencha中使用id来选择组件,并且在可能的情况下这样做是一个好主意,以保持事物的可重用性并避免污染全局id空间,那么您有几个选项 粗体部分取自Sencha文档,其余部分是我的 getComponent方法:检查此容器的items属性并获取此容器的直接子组件。基本上,传入一个字符串,该字符串应与容器中某个项的id或itemIdproperty匹配 Ex

Ext.getCmp'segmentWidget'.setPressedButtons0

我如何在不使用ID的情况下执行此操作

谢谢

如果您不想在Sencha中使用id来选择组件,并且在可能的情况下这样做是一个好主意,以保持事物的可重用性并避免污染全局id空间,那么您有几个选项

粗体部分取自Sencha文档,其余部分是我的

getComponent方法:检查此容器的items属性并获取此容器的直接子组件。基本上,传入一个字符串,该字符串应与容器中某个项的id或itemIdproperty匹配

Ext.Container.query方法:检索与传递的选择器匹配的所有子体组件。使用此容器作为其根执行Ext.ComponentQuery.query。这将返回Ext.Component的数组。查看Ext.ComponentQuery.querydocs以了解可以执行哪些查询。简而言之,您只需通过xtype进行选择,在您的情况下,您可以执行以下操作:fatherComponent.query'segmentedbutton'[0],或者通过另一个属性进行选择,例如:fatherComponent.query'[text=text1]'[0]

Ext.Component.up方法:沿着ownerCt轴查找与传递的简单选择器匹配的祖先容器


我想你可以将这个问题改为更一般的问题,这并不仅仅是关于segmentedbutton,而是关于根据属性而不是IDS选择组件。你能对我的答案给出一些反馈吗?你觉得它有用吗?
Code:

     items: [{
            xtype: 'segmentedbutton',
            disabled: true,
            //id:'segmentWidget',
                    items: [
                        {
                            text: 'text1',
                            flex: 1,
                        },
                        {
                            text: 'text2',
                            flex: 1
                        },
                        {
                            text: 'text2',
                            flex: 1
                        }
                    ]

        }]