Javascript 为什么要获取错误数据。findIndex不是React with Redux项目中的函数?
我有一个带有React和Redux的ASP.NET核心项目,我也在使用Kendo React UI。我正在尝试将数据返回到我的剑道小部件中,但当我尝试返回数据时出现错误,我需要帮助确定我做错了什么 当我运行我的应用程序时,我得到以下错误: 页面TypeError上的2个错误中的1个错误:data.findIndex不是函数 DropDownList/_this.renderDropDownWrapper C:/Users/Allan/node_modules/@progress/kendo react dropdowns/dist/es/DropDownList/DropDownList.js:83 80 | var聚焦=_this.state.focused;81 | var打开= _此.props.opened!==未定义_this.props.opened:_this.state.opened;82 | var值=_此值 83 | var selectedIndex=data.findIndex函数i{返回areSamei,value,dataItemKey;};84 | var文本= getItemValuevalue,文本字段;85 | var valueDefaultRendering= React.createElementspan,{className:k-input},文本;86 | var valueElement=valueRender!==未定义 在控制台中,此错误显示为: 警告:失败的道具类型:字符串类型的道具数据无效 提供给DropDownList,应为阵列 这个错误是有道理的,但是我返回的数据应该是一个数组。它不是,因为它似乎没有返回任何东西。所以我做错了什么 这是到目前为止我的代码,请注意,我的数据是从通用存储库提供的 组件/容器/WidgetData.js 最后,在存储中定义减速器 组件/store/configureStore.jsJavascript 为什么要获取错误数据。findIndex不是React with Redux项目中的函数?,javascript,reactjs,asp.net-core,redux,kendo-ui,Javascript,Reactjs,Asp.net Core,Redux,Kendo Ui,我有一个带有React和Redux的ASP.NET核心项目,我也在使用Kendo React UI。我正在尝试将数据返回到我的剑道小部件中,但当我尝试返回数据时出现错误,我需要帮助确定我做错了什么 当我运行我的应用程序时,我得到以下错误: 页面TypeError上的2个错误中的1个错误:data.findIndex不是函数 DropDownList/_this.renderDropDownWrapper C:/Users/Allan/node_modules/@progress/kendo re
我已经测试了API以确保数据在那里并且可以正常工作,我已经从商店中的Types.js将所述数据记录到控制台,并且可以看到返回的数据。我对redux的反应非常陌生,因此我尝试在这里找到自己的方法,非常感谢您的帮助。您需要删除以下状态定义,因为您希望引用redux存储中的值,而不是本地值:
class WidgetData extends Component {
state = {
vesseltypes: ""
};
然后,在代码中,需要参考redux存储值:this.props.vesseltypes:
你好,尤西,谢谢你的密码。如果我在您提到的地方更改代码并删除本地值,我会得到一个错误:“state”未定义。这是有道理的,因为我已经删除了您提到的局部值。你能确认是否应该定义状态吗?你能把所有修改过的代码都放在问号中,并在错误出现的地方打上标记吗?
const requestVesselTypes = 'REQUEST_TYPES';
const receiveVesselTypes = 'RECEIVE_TYPES';
const initialState = {
vesseltypes: [],
isLoading: false
};
export const actionCreators = {
requestTypes: () => async (dispatch) => {
dispatch({ type: requestVesselTypes });
const url = 'api/KendoData/GetVesselTypes';
const response = await fetch(url);
const alltypes = await response.json();
dispatch({ type: receiveVesselTypes, alltypes });
}
}
export const reducer = (state, action) => {
state = state || initialState;
if (action.type === requestVesselTypes) {
return {
...state,
isLoading: true
};
}
if (action.type === receiveVesselTypes) {
alltypes = action.alltypes;
return {
...state,
vesseltypes: action.alltypes,
isLoading: false
}
}
return state;
};
const reducers = {
vesseltypes: Types.reducer
};
class WidgetData extends Component {
state = {
vesseltypes: ""
};
class WidgetData extends Component {
state = {
vesseltypes: ""
};
componentWillMount() {
this.props.requestTypes();
}
render() {
return (
<div>
<DropDownList data={this.props.vesseltypes} />
</div>
);
}
}
export default connect(
vesseltypes => state.vesseltypes,
dispatch => bindActionCreators(actionCreators, dispatch)
)(WidgetData);