项目中遇到Cannot read property 'length' of null

错误页面:

项目中遇到Cannot read property 'length' of null

本人遇到的这个错误的原因主要是后台返回给页面的数据错误,没有数据时我返回给前台页面的是null,所以这个时候前台就会报这个Cannot read property ‘length’ of null的错误提示,当没有数据时正确的返回格式应该是一个空集合,这样才不会报错。

修改前的后台代码(报错):

项目中遇到Cannot read property 'length' of null

接口回调结果:

项目中遇到Cannot read property 'length' of null

修改后的后台代码(正确):

项目中遇到Cannot read property 'length' of null

接口回调结果:

项目中遇到Cannot read property 'length' of null