SelectorQuery.in
将节点的选取范围更改为指定的自定义组件内。未使用 SelectorQuery.in
的场景下,并不会选取任何自定义组件内的节点。
语法
selectorQuery.in(component)
参数说明
Component component
自定义组件的实例对象。
获取方式:
- 在
Page
或Component
中调用 this.selectComponent 方法 - 在
Component
中直接使用this
对象
返回值
扫码体验
请使用字节宿主APP扫码
代码示例
TTML
<view>
<my-component id="myComponent"></my-component>
</view>
JavaScript
Page({
onReady() {
const myComponent = this.selectComponent("#myComponent");
// 将节点选取范围限定在 myComponent 中
const query = tt.createSelectorQuery().in(myComponent);
// 选取一个节点
query.select("#some-node").boundingClientRect();
query.exec(function (res) {
// 打印所选节点的宽度和高度
console.log(res[0].width, res[0].height);
});
},
});
点击纠错
评价此篇文档