安全上下文
此特征只可用于 安全上下文 (HTTPS),在某些或所有 支持浏览器 .

XRInputSourceArray 方法 forEach() executes the specified callback once for each input source in the array, starting at index 0 and progressing until the end of the list.

句法

xrInputSourceArray.forEach(callback, thisArg);
					

参数

callback

A function to execute once for each entry in the array xrInputSourceArray . The callback accepts up to three parameters:

currentValue
A XRInputSource object which is the value of the item from within the xrInputSourceArray which is currently being processed.
currentIndex 可选
An integer value providing the index into the array at which the element given by currentValue is located. If you don't need to know the index number, you can omit this.
sourceList 可选
XRInputSourceArray object which is being processed. If you don't need this information, you may omit this.
thisArg 可选
The value to be used for this while executing the callback. Note that if you use arrow function notation ( => ) to provide the callback, you can omit thisArg , since all arrow functions lexically bind this .

返回值

Undefined.

范例

This example snippet gets the list of inputs for a session and tries to handle each type of input device it supports using.

let inputSources = xrSession.inputSources;
inputSources.forEach((input) => {
  if (input.gamepad) {
    checkGamepad(input.gamepad);
  } else {
    if (input.targetRayMode === "tracked-pointer" &&
        input.handedness === player.handedness) {
      /* Handle main hand controller */
      handleMainHandInput(input);
    } else {
      /* Handle other inputs */
    }
  }
});
					

For each input in the llist, the callback dispatches gamepad inputs to a checkGamepad() with the input's Gamepad object, taken from its gamepad property, as an input

For other devices, we look for tracked-pointer devices in the player's main hand, dispatching those to a handleMainHandInput() 方法。

规范

规范 状态 注释
WebXR 设备 API
The definition of 'XRInputSourceArray' in that specification.
1
工作草案 XRInputSourceArray interface

[1] Iterator-like methods in Information contained in a WebIDL file for information on how an iterable declaration in an interface definition causes entries() , forEach() , keys() ,和 values() methods to be exposed from objects that implement the interface.

浏览器兼容性

更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
forEach() Chrome 79 Edge 79 Firefox No IE No Opera No Safari No WebView Android No Chrome Android 79 Firefox Android No Opera Android No Safari iOS No Samsung Internet Android 11.2

图例

完整支持

完整支持

不支持

不支持

另请参阅

元数据

  • 最后修改: