首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Blueprint选择值字段

Blueprint选择值字段
EN

Stack Overflow用户
提问于 2018-06-01 05:25:18
回答 1查看 4.5K关注 0票数 1

我正在使用BlueprintJs Select组件,它能够渲染。但是,它不会像应该显示的那样显示任何值文本。我不确定为什么它没有显示出来。因为Select使用的是InputGroup,所以文档说要使用inputProps来设置值和onchange函数,但这似乎不起作用。我的代码如下

代码语言:javascript
复制
import React from 'react';
import { Select } from '@blueprintjs/labs';
import { MenuItem, Button } from '@blueprintjs/core';
import PropTypes from 'prop-types';

class BlueprintSelect extends React.Component {
  constructor(props) {
    super(props);
    const elementSelectItems = [
      { id: 1, query: 'term(s)' },
      { id: 2, query: 'range' },
    ];
    this.state = {
      elementSelectItems,
      selectedValue: elementSelectItems[0].query,
    };
  }

  handleElementSelect = ({ query }) => {
    console.log('printint our', query);
  }

  renderSelect = ({ handleElementSelect, item }) => (
    <MenuItem
      key={item.id}
      label={item.query}
      onClick={handleElementSelect}
      text={item.query}
      shouldDismissPopover
    />
  )

  render() {
    const elementSelectItems = [
      { id: 1, query: 'term(s)' },
      { id: 2, query: 'range' },
    ];
    return (
      <div className="elementSelector">
        <Select
          inputProps={{ value: this.state.selectedValue, onChange: this.handleElementSelect }}
          items={elementSelectItems}
          filterable={false}
          itemRenderer={this.renderSelect}
          onItemSelect={this.handleElementSelect}
          noResults={<MenuItem disabled text="No results." />}
        >
          <Button className="querySelectButton" text="query Type" rightIconName="caret-down" />
        </Select>
      </div>
    );
  }
}

为什么当我选择两个菜单项中的一个时,尤其是在使用Select组件的inputProps属性实现受控状态时,该值无法显示?

EN

回答 1

Stack Overflow用户

发布于 2018-10-15 23:17:10

在示例中,他们设置了Section组件的嵌套子按钮的text属性中的值。这里有一个https://blueprintjs.com/docs/#select/select-component示例。我会这样做:

代码语言:javascript
复制
<Section> ... <Button text={this.state.selectedValue || elementSelectItems[0].value} /></Section>
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50633012

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档