gpt4 book ai didi

javascript - 如何将数组传递给material-ui dataSource props

转载 作者:行者123 更新时间:2023-12-03 05:55:52 25 4
gpt4 key购买 nike

我正在使用material-ui作为组件。 Material-ui 中有一个自动完成组件,我想用它来显示带有图标的图标名称列表。如果我只将 MenuItem 传递给 dataSource,我会得到一个没有列表的空输入框。如果我尝试像我的代码中那样传递键和值,我会收到意外 token 的错误。

这是我的代码

console.log('this.props.fetchIcon', this.props.fetchIcon.icons);
const listOfIcon = _.map(this.props.fetchIcon.icons, (icon) => {
return (text: {icon.name}, value: (<MenuItem primaryText={icon.name} secondaryText={icon.name} />));
});
return (
<div className="device-action">
<Dialog
title="Add a Tab"
actions={actions}
modal={false}
open={this.props.createTab.open}
onRequestClose={this.props.CancelDeviceEvent}
>
<div className="icon">
<AutoComplete
floatingLabelText="select any icon"
filter={AutoComplete.noFilter}
openOnFocus
dataSource={listOfIcon}
/>
</div>
</Dialog>
</div>
);

reducer

const initialState = {
fetching: false,
fetched: true,
icons: [],
error: null,
};

export const fetchIconReducer = (state = initialState, action) => {
switch (action.type) {
case 'FETCH_ICONS_START':
return { ...state, fetching: true };
case 'FETCH_ICONS_ERROR':
return { ...state, fetching: false, error: action.payload };
case 'RECIEVE_ICONS':
return { ...state, fetching: false, fetched: true, icons: action.payload };
default:
return state;
}
};

this.props.fetchIcon.icons 控制台如下

enter image description here

最佳答案

您应该为dataSource返回一个对象数组。尝试以下操作..

_.map(this.props.fetchIcon.icons, (icon) => {
return {
text: icon.name,
value: <MenuItem primaryText={icon.name} secondaryText={icon.name} />
}
});

关于javascript - 如何将数组传递给material-ui dataSource props,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39932671/

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