2014-04-16 19 views
0

我有一個谷歌自動完成搜索框,不斷更新搜索。 下面的代碼適用於兩個搜索,然後我得到一個findQuery的響應必須是一個數組,而不是未定義。Emberjs:UPDATED findQuery的響應必須是一個Array,而不是undefined

卸載每個新搜索的商店地址和酒店數據可能不是一件好事。但現在我想不出任何其他解決方案。

Lost.HotelRoute = Ember.Route.extend({ 
queryParams: { 
    currentPlace: { 
     refreshModel: true 
    } 
}, 
model: function (params) { 
    var self = this; 
    var hotelController = this.controllerFor('hotel'); 
    var currentPlace = hotelController.get('currentPlace'); 
    self.store.unloadAll('address'); 
    self.store.unloadAll('hotel'); 
    return this.store.find('address', { 
     locality: currentPlace 
    }).then(function (response) { 
     return self.store.all('hotel'); 
    }); 
}, 
deactivate: function() { 
    this.controllerFor('city').set('routeNeedsAutoSearch', false); 
} 

});

+0

是'找到(「地址」,{currentPlace})'一個錯字我可能不適合我學習這麼?它應該是'find('address',{locality:currentPlace})'如上? – claptimes

+0

感謝它('地址',currentPlace),因爲我的組件傳遞適當的對象。仍然存在相同的錯誤 – Rigel

回答

0

我改變了我的方法。 我想這是一個很好的方式來卸載每個搜索的數據。 更好的方法是用戶this.store.filter 所以我現在正在做這樣的事情。

如果有一個人提出一個更好的任何我將選擇適當的答案

return this.store.find('address', { 
    locality: currentPlace 
}).then(function (response) { 
     response.forEach(function (item) { 
      addressId = item.get('id'); 
      arr = self.store.filter('hotel', function (hotel) { 
      return hotel.get('address.id') == addressId; 
     }); 
    }); 
}); 
相關問題