JavaScript parseInt() radix函数

12 min read

parseInt() 函数解析字符串并返回整数。 radix 参数用于指定使用哪种数字系统,例如基数为16(十六进制)表示字符串中的数字应从十六进制数解析为十进制数。 如果radix 参数被省略,JavaScript 假定如下: 如果字符串以"0x" 开头,则基数为16(十六进制)

  const changeTemplate = (item) => {
    const index = parseInt(item.key, 10);
    const {themeId, css} = this.props.content.themeList[index];
    this.props.navbar.setTemplateNum(index);

    // 更新style编辑器
    if (themeId === "custom") {
      this.props.content.setCustomStyle();
      // 切换自定义自动打开css编辑
      this.props.view.setStyleEditorOpen(true);
    } else {
      this.props.content.setStyle(css);
    }
  };