Node.js 在ChereIO中使用WithStartIndexes选项时,element.startIndex未定义

Node.js 在ChereIO中使用WithStartIndexes选项时,element.startIndex未定义,node.js,cheerio,Node.js,Cheerio,当使用ChereIO解析HTML时,我需要节点的startIndex,因此我使用以下代码指示ChereIO根据说明添加该属性,并且: 在网上搜索并翻阅Cheerio的代码后,我发现Cheerio默认使用的是。为了获得startIndex属性,您必须通过将xmlMode选项设置为true来指示Cheerio使用: const options = { xmlMode: true, withStartIndices: true } const html = ` <template>

当使用ChereIO解析HTML时,我需要节点的
startIndex
,因此我使用以下代码指示ChereIO根据说明添加该属性,并且:


在网上搜索并翻阅Cheerio的代码后,我发现Cheerio默认使用的是。为了获得
startIndex
属性,您必须通过将
xmlMode
选项设置为
true
来指示Cheerio使用:

const options = {
  xmlMode: true,
  withStartIndices: true
}

const html = `
<template>
  <h1>Hello!</h1>
</template>
<script>
  const foo = () => {
    console.log('bar')
  }
</script>
<style>
  h1{
    color:blue;
  }
</style>
`;

const $ = cheerio.load(html, options);
console.log( $('#element')[0].startIndex );

万岁

无法与StartIndexes一起使用:在最新的ChereIOS中为true我使用npm i ChereIO安装它。您能告诉我在哪个版本下该功能正常吗?在
v0.22.0
中,它似乎对我有效。您正在尝试使用哪个版本?“^1.0.0-rc.3”我也使用typescript@types/cheerio,因为typescript可能(带起始索引)不起作用……当我尝试不使用@types/cheerio时,它起作用是因为@types/cheerio的问题吗?在这种情况下,“不起作用”是什么意思?运行代码时是否存在Typescript错误或实际的功能差异?它给出的错误在编译时不存在WithStartIndexes属性
undefined
const options = {
  xmlMode: true,
  withStartIndices: true
}

const html = `
<template>
  <h1>Hello!</h1>
</template>
<script>
  const foo = () => {
    console.log('bar')
  }
</script>
<style>
  h1{
    color:blue;
  }
</style>
`;

const $ = cheerio.load(html, options);
console.log( $('#element')[0].startIndex );
110