Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Json 无法读取属性';地图';react datatable错误中未定义的值_Json_Node.js_Reactjs_React Router - Fatal编程技术网

Json 无法读取属性';地图';react datatable错误中未定义的值

Json 无法读取属性';地图';react datatable错误中未定义的值,json,node.js,reactjs,react-router,Json,Node.js,Reactjs,React Router,在映射函数中获取错误 generateRows: function() { var cols = this.props.cols, // [{key, label}] data = this.props.data; 获取数据时出错(获取未定义的值) 返回数据.map(函数(项){ //处理每行中的列数据 var cells=cols.map(函数(colData){ //colData.key可能是“firstName” 返回{item[colData.key]};

在映射函数中获取错误

 generateRows: function() {
    var cols = this.props.cols,  // [{key, label}]
        data = this.props.data;
获取数据时出错(获取未定义的值)

返回数据.map(函数(项){
//处理每行中的列数据
var cells=cols.map(函数(colData){
//colData.key可能是“firstName”
返回{item[colData.key]};
});
返回{cells};
});
},

由于您是从道具中获取COL,为了确保它们存在于initialRender中,您可以添加一个检查,并在单个语句中返回映射,如

 return data && data.map(function(item) {

        // handle the column data within each row

        return <tr key={item.BlogId}> {cols && cols.map(function(colData, index) {
            // colData.key might be "firstName"
            return <td key={index}> {item[colData.key]} </td>;
        })} </tr>;
    });
返回数据和&data.map(函数(项){
//处理每行中的列数据
返回{cols&&cols.map(函数(colData,index){
//colData.key可能是“firstName”
返回{item[colData.key]};
})} ;
});

还为从内部映射函数返回的元素提供一个键

这是返回数据的
位置。映射
?在尝试映射数据之前,请确保数据存在。在getInitialState方法中设置数据,然后使用itHow在getInitialState中设置数据。实际上,它是在调用generateRows方法之后设置的,这就是为什么当前会出现错误;var viewDBData=DBData.ViewBlog(“”,函数(val,responseMessage){data=JSON.stringify(JSON.parse(val.result);});并将this.props.data的值设置为data=data
 return data && data.map(function(item) {

        // handle the column data within each row

        return <tr key={item.BlogId}> {cols && cols.map(function(colData, index) {
            // colData.key might be "firstName"
            return <td key={index}> {item[colData.key]} </td>;
        })} </tr>;
    });