sencha touch 如何获得list中选中项的元素(element)

原理:通过使用Ext.select()方法选中list中选中的item的元素

原文:http://www.sencha.com/forum/showthread.php?174989-get-list-item-component-x-y-position-in-an-item-tap-event

Sencha Touch 交流 QQ 群 224711028 欢迎您的加入。

文档源代码:

//get my view, which is just a sized down Ext.Sheet
varview = this.getItemMenuView().create();
 
 
//note that the quotes around the itemindex value here are required to include and don't seem to be in the sencha docs; this function was failing until I included the quotes
varitemEl = Ext.select("div.x-list-item[itemindex=\""+ idx + "\"]", listCmp.getId() );
 
//I know that the array returned by Ext.select above will only ever be a single element array, so we just grab the first element here
varel = itemEl.first();
 
 
varx = el.getX();    
vary = el.getY();
varsize = el.getSize();
 
 
x = x + size.width / 2;
y = y + size.height;
 
 
view.setTop(y);
view.setLeft(10);
 
 
view.show();
 
 
}

?

获得element后我们可以对元素进行附加样式的操作:

varitemEl = Ext.select(".x-item-selected", myApp.getSectionList().getId() );
                    varel = itemEl.first();
                    console.log(itemEl);
                    console.log(el);
                    Ext.get(el).addCls('search-item-active');

?

附:Ext.select方法API:

String/HTMLElement[] selector, [HTMLElement/String root] ) :  Ext.dom.CompositeElementLite

Selects elements based on the passed CSS selector to enable Element methods to be applied to many related elements in one statement through the returned CompositeElementLite object.

Parameters

  • selector : String/HTMLElement[]

    The CSS selector or an array of elements

  • root : HTMLElement/String (optional)

    The root element of the query or id of the root

Returns

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值