gpt4 book ai didi

javascript - 我是否必须将 TypeScript 与 Blueprint.js 中的 MultiSelect(实验室)组件一起使用

转载 作者:搜寻专家 更新时间:2023-10-30 21:29:14 25 4
gpt4 key购买 nike

我正忙于试验 Blueprint.js 和 MultiSelect 组件,据我所知,它仍在积极开发中:http://blueprintjs.com/docs/#labs.multiselect

我从来没有使用过 TypeScript,据说是

// Select<T> is a generic component to work with your data types.
// In TypeScript, you must first obtain a non-generic reference:
const FilmSelect = Select.ofType<Film>();

所以我的问题是,是否可以在不使用 TypeScript 的情况下在 Javascript 中使用此组件?

我的react组件目前没有渲染,错误如下:

multiSelect.js?64c9:37 Uncaught TypeError: Cannot read property 'map' of undefined

组件定义为:

import React from 'react';
import Flexbox from 'flexbox-react';
import {Dialog, Button, Intent} from '@blueprintjs/core';
import {MultiSelect} from '@blueprintjs/labs';
import {inject, observer} from 'mobx-react';
import Avatar from 'react-avatar';

@inject('AccountRelationshipsStore', 'AccountUsersStore', 'ToastStore')@observer
export default class AccountRelationshipsNewRelationship extends React.Component {
constructor(props) {
super(props);

this.state = ({isSubmitting: false});
}

renderUser(handleClick, isActive, user) {
return (
<span>{user.fullName}</span>
);
}

renderTag(user) {
return user.fullName;
}

handleItemSelect(item) {
console.log(item);
}

render() {
return (
<Dialog isOpen={this.props.dialogOpen} onClose={() => this.props.toggleDialog()} canOutsideClickClose={true} title={I18n.t('js.add_a_new_user_relationship', {
type: this.props.AccountRelationshipsStore.activeRelationship.name.toLowerCase(),
name: this.props.AccountRelationshipsStore.activeUser.fullName
})} className='side-dialog' inline={true}>
<form>
<div className='pt-dialog-body'>
<Flexbox flexDirection='column' flexGrow={1}>
<Flexbox flexDirection='row' justifyContent='center' flexGrow={1}>
<Avatar src={this.props.AccountRelationshipsStore.activeUser.imageFileName} size={100} round={true} className=''/>
</Flexbox>
<Flexbox flexDirection='row' justifyContent='center' flexGrow={1} marginTop='10px'>
<p className='pt-text-muted'>{this.props.AccountRelationshipsStore.activeUser.fullName}</p>
</Flexbox>
<Flexbox>
<MultiSelect items={this.props.AccountUsersStore.users} itemRenderer={this.renderUser.bind(this)} onItemSelect={this.handleItemSelect.bind(this)} tagRenderer={this.renderTag.bind(this)}/>
</Flexbox>
</Flexbox>
</div>
<div className='pt-dialog-footer pt-dialog-footer-bottom'>
<div className='pt-dialog-footer-actions'>
<Button text={I18n.t('js.cancel')} onClick={() => this.props.toggleDialog()}/>
<Button intent={Intent.PRIMARY} type='submit' text={I18n.t('js.set_relationships')} loading={this.state.isSubmitting}/>
</div>
</div>
</form>
</Dialog>
);
}
}

最佳答案

是的,您可以将组件与 JS 一起使用。只需省略通用类型参数:

const UserMultiSelect = MultiSelect.ofType();

<UserMultiSelect items={this.props.AccountUsersStore.users} ... />

我承认这有点不直观,因此可能需要更新文档。

关于javascript - 我是否必须将 TypeScript 与 Blueprint.js 中的 MultiSelect(实验室)组件一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45594452/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com