在使用GridManager的时候,有时会出现以下错误:
GridManager Error: response.data is not Array,please check dataKey
解决方法
这个错误是由于返回的data并不是一个数组,并提示检查配置项dataKey。
如果dataKey与接口返回字段不匹配,那么组件通过dataKey获取到的将是undefined。
比如接口返回格式如下:
{
list: [
{name:'baukh', age: 11},
{name:'baukh2', age: 22}
]
}
由于dataKey默认值为data,当接口返回的数组字段为list时就需要在初始化时添加配置项: dataKey: 'list'。
详情可参考API - dataKey
如果当前未配置dataKey: 'list',将会报出GridManager Error: response.data is not Array,please check dataKey错误。
除此之外配置项responseHandler也可以处理该问题,但responseHandler一般用于处理更为复杂的情况。