我正在研究一個權限系統,讓用戶可以控制誰可以訪問/評論/編輯資源,就像您可以在Google雲端硬盤上找到的一樣。我正在使用React-Select multi來讓資源的所有者選擇他想要訪問資源的用戶。反應選擇明確的值,同時保持過濾器
當我點擊react-select顯示的選項時,我希望將此選項添加到允許的用戶列表(由另一個組件處理的列表)中。這部分起作用,我只是在select上使用了onChange處理程序(就像你在下面的代碼中看到的那樣)。
export default class AddUsersForm extends Component {
PropTypes = {
onSubmit: PropTypes.func.isRequired,
usersList: PropTypes.array.isRequired, // List of all users in the company
usersInPermissions: PropTypes.array.isRequired, // Users who already have access to the resource
}
handleChange(users){
// Adds new user to the list of allowed users, an updated value for this.props.usersInPermissions will be received
this.props.onSubmit(users);
}
render() {
return (
<form>
<Select
name="users"
multi={true}
options={this.props.usersList.filter(user => !this.props.usersInPermissions.includes(user.id))}
onChange={(users) => this.handleChange(users)}
/>
</form>
);
}
}
這是我堅持:一旦選項已被添加,我想保持顯示,雖然搜索文本的第一個選項的用戶是可能使用的過濾器領域。現在它的工作方式是刪除過濾器,並在下拉菜單中顯示所有選項。
有沒有簡單的方法來實現這與React-Select?
非常感謝!
我想從價值刪除嗎?你能解釋一下嗎? – Ved
你檢查了https://github.com/JedWatson/react-select/blob/master/examples/src/components/Multiselect.js嗎? – elmeister
@Ved我真的很困惑,這沒有任何意義!所以我唯一的問題是實際上保持過濾器在那裏,你知道是否有辦法做到這一點? – notten13