您的位置:首页 > 其它

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

2012-06-10 01:36 537 查看
原理:通过使用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:

select( 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

Ext.dom.CompositeElementLite
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: