SelectorQuery.selectAll

解释: 在当前页面下选择匹配选择器 selector 的节点,返回一个 NodesRef 对象实例。 与 selectorQuery.select(selector) 不同的是,它选择所有匹配选择器的节点。

# 方法参数

String selector

# 返回值

NodesRef

# 示例

扫码体验
重新加载
请使用百度APP扫码

# 图片示例

# 代码示例

    <view class="wrap">
        <view class="card-area">
            <movable-area>
                <movable-view class="target" x="{{x}}" y="{{y}}" direction="all" bindchange="queryNodeInfo">
                    targetFirst
                </movable-view>
            </movable-area>
        </view>
        <view class="card-area">
            <movable-area>
                <movable-view class="target" x="{{x}}" y="{{y}}" direction="all" bindchange="queryNodeInfo">
                    targetSecond
                </movable-view>
            </movable-area>
        </view>
    
         <view class="list-area border-bottom">
            <text class="list-item-key-4">
                targetFirst:
            </text>
            <text class="list-item-value-4">
                {{targetFirst}}
            </text>
        </view>
        <view class="list-area border-bottom">
            <text class="list-item-key-6">
                targetSecond:
            </text>
            <text class="list-item-value-4">{{targetSecond}}</text>
        </view>
    </view>
    
    Page({
        data: { 
            targetFirst: '',
            targetSecond: ''
        },
        onReady() {
            this.queryNodeInfo();
        },
        queryNodeInfo() {
            const selectorQuery = swan.createSelectorQuery();
            selectorQuery.selectAll('.target').boundingClientRect();
            selectorQuery.exec(res => {
                this.setData('targetFirst', res[0][0].top);
                this.setData('targetSecond', res[0][1].top);
            });
        }
    });