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

XRInputSourceArray 接口的 entries() method returns a JavaScript iterator which can then be used to iterate over the key/value pairs in the input source array. Each item in the array is an XRInputSource 对象。

Most frequently, you will use this in tandem with statements such as for...of .

句法

let inputSourceIterator = xrInputSourceArray.entries();
for (let entry of xrInputSourceArray.entries()) {
  /* ... */
}
					

参数

None.

返回值

An iterator which can be used to walk through the list of XRInputSource objects included in the input source array.

范例

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

let sources = xrSession.inputSources;
for (let input of sources.entries()) {
  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, gamepad inputs are dispatched 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
entries() 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

图例

完整支持

完整支持

不支持

不支持

元数据

  • 最后修改: