0
我有用戶的清單,當我點擊複選框時,用戶應該添加到InputField或從InputField刪除,如果我再次檢查它。從數組中刪除項目(React-Native + Redux)
現在只適用於ADD。
import ...
export default class NewEvent extends React.Component {
constructor(props) {
super(props);
this.onSelect = this.onSelect.bind(this);
}
onSelect = id => {
addMembers(id) }
findSelectedContacts = (contacts, membersArray) => {
const newArr = [];
contacts.forEach(item => {
if(membersArray.indexOf(item.id.toString()) > -1) {
newArr.push(` ${item.name}`)
}
});
return newArr;
}
render() {
const { navigation, members, location, contacts } = this.props;
const membersArray = members ? members.split(',') : [];
const selectedArray = this.findSelectedContacts(contacts, membersArray)
const inputFill = selectedArray.join().trim();
return (
<InputField
customStyle={[eventStyles.input]}
icon="addGuest"
placeholder="Add guests"
onGetText={texts => {
this.handlerChangeText(texts)
}}
value={inputFill}
/>
);
}
}
另外,我有減速,增加了客人輸入:
import { handleActions } from 'redux-actions';
import * as types from '../actions/actionTypes';
export const initialState = {
members: '',
};
const addMembers = (members, id) => {
const res = members ? `${members},${id}` : `${id}`;
return res;
}
export default handleActions(
{
[types.ADD_GUEST]: (state, action) => ({
...state,
members: addMembers(state.members, action.payload),
}),
},
initialState
);
請指教,我怎樣才能改變我減速?如果我點擊ONE複選框,我需要從InputFiled添加或刪除用戶。
我的理解,我需要通過removeMember像道具的地方,不要我 –
不完全是你確實需要派遣與動作。鍵入'types.REMOVE_G UEST'和'id'的負載,然後reducer會爲你調用'removeMember'方法。 – jevakallio
我問,因爲我使用了你的代碼,它只添加成員但不刪除它。 –