NDEFRecord:data 属性
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
NDEFRecord
接口的 data
属性会返回一个 DataView
,其中包含记录有效载荷的原始字节。
语法
js
NDEFRecord.data
值
DataView
,其中包含记录的编码有效载荷数据。
示例
下面的示例循环遍历了 NDEFMessage
对象中的记录,该对象是从 NDEFReadingEvent.message
中获取的。根据 mediaType
选择记录后,会对 data
属性中存储的内容进行解码。
js
const ndef = new NDEFReader();
await ndef.scan();
ndef.onreading = (event) => {
const decoder = new TextDecoder();
for (const record of event.message.records) {
if (record.mediaType === "application/json") {
const json = JSON.parse(decoder.decode(record.data));
const article = /^[aeio]/i.test(json.title) ? "an" : "a";
console.log(`${json.name} is ${article} ${json.title}`);
}
}
};
规范
Specification |
---|
Web NFC API # dom-ndefrecord-data |
浏览器兼容性
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
data |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
- No support
- No support
- Experimental. Expect behavior to change in the future.
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.