From 4d8b0646f0b6a06fd13563b5c1f07d175942c4b5 Mon Sep 17 00:00:00 2001 From: jjeejj Date: Sat, 5 May 2018 14:53:34 +0800 Subject: [PATCH] =?UTF-8?q?fixed=20#60=20=E8=87=AA=E5=A6=82=E6=88=BF?= =?UTF-8?q?=E6=BA=90=E8=BF=94=E5=9B=9E=E6=95=B0=E6=8D=AE=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- routes/ziroom/room.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/routes/ziroom/room.js b/routes/ziroom/room.js index 45f7bf7e5..d3d298a2f 100644 --- a/routes/ziroom/room.js +++ b/routes/ziroom/room.js @@ -27,8 +27,9 @@ module.exports = async (ctx) => { 'step': 0 }), }); - - const data = response.data.data; + let data = response.data.data; //当查询的结果不存在时,该 data 是个对象 { info: '数据加载完毕' } + //判断数据的类型,如果有数据就是数组类型的,没有数据的话,就赋值为空数组 + data = (data instanceof Array) ? data : [{title:"我们找不到任何与您的搜索条件匹配的结果,但是调整您的搜索条件可能会有所帮助",room_name:"",list_img:"",city:"",id:""}]; ctx.body = art(path.resolve(__dirname, '../../views/rss.art'), { title: `自如的${keyword}${iswhole ? '整租' : '合租'}${room}室房源`, @@ -41,4 +42,4 @@ module.exports = async (ctx) => { link: `http://${domain}/${city.toUpperCase()}/room/${item.id}.html` })), }); -}; \ No newline at end of file +};