reactjs 使用listItems中的实际数据渲染fileContent

e4eetjau  于 11个月前  发布在  React
关注(0)|答案(2)|浏览(84)

在这个render函数中,我从SharePoint中的列表中检索数据并呈现fileContent,但属性没有从listItems中替换
下面是我尝试的render函数的代码:

public render(): React.ReactElement<ILinkItemsWithReactProps> {
    return (
      <div className={styles.linkItemsWithReact}>
        <ol>
          {this.state.listitems.map((listitem, listitemkey) => {
            console.log(this.state.listitems);
            return (
              <li key={listitemkey}>
                <a>{this.state.fileContent}</a>
              </li>
            );
          })}
        </ol>
      </div>
    );
  }

字符串
我想渲染一个特定模板的fileContent,并从listItems的实际数据中显示该模板的属性。

vmpqdwk3

vmpqdwk31#

您没有使用map回调提供的值,而是使用了其他一些状态。
如果将listitem.content中的content替换为正确的属性,则以下代码应该可以工作。
另外,Array.prototype.map()回调函数的第二个参数是数组中的index,所以我也改变了它。

return (
  <div className={styles.linkItemsWithReact}>
    <ol>
      {this.state.listitems.map((listitem, index) => {
        return (
          <li key={index}>
            <a>{listitem.content}</a> // TODO: replace content with the actual attribute
          </li>
        );
      })}
    </ol>
  </div>
);

字符串

tkqqtvp1

tkqqtvp12#

看起来像是在this.state.listitems上迭代,但除了作为关键属性之外,没有使用它们。
你的意思是在循环中渲染listitem.fileContent或类似的东西吗?

相关问题