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

keys() 方法在 XRInputSourceArray interface returns a JavaScript iterator which can then be used to iterate over the keys used to reference each item in the array of input sources.

句法

xrInputSourceArray.keys();
					

参数

None.

返回值

A JavaScript iterator that can be used to walk through the keys for each entry in the list of input sources. The values returned by the iterator are the indexes of each entry in the list; that is, the numbers 0, 1, 2, and so forth through the index of the last item in the list.

范例

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

for (const inputIdx of xrSession.inputSources.keys()) {
  /* the keys are the indexes into the list of inputs */
  checkInput(xrSession.inputSources[inputIdx]);
}
					

这里, for...of is used to iterate over each of the keys. For each key, the input is retrieved using the index with array notation: xrSession.inputSources[inputIdx] .

规范

规范 状态 注释
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
keys 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

图例

完整支持

完整支持

不支持

不支持

另请参阅

元数据

  • 最后修改: