2016-04-21 9 views
0

我目前正在瀏覽ember.js指南,並且我正在掛上Ember Data部分。 Ember Data GuideEmber處理路由時出現數據錯誤this.store.findALL不是函數

本教程演示如何創建Ember數據模型,並將其與幻影結合使用以在索引頁上呈現一些基本租賃信息。

我的代碼看起來是一樣的教程(見底注),但我的索引頁面不顯示任何內容,我在Chrome控制檯中看到這些錯誤:enter image description here


任何幫助的人可以提供將非常感激。


這是我應用程序/模型/ rentals.js

import Model from 'ember-data/model'; 
import attr from 'ember-data/attr'; 

export default Model.extend({ 
    title: attr(), 
    owner: attr(), 
    city: attr(), 
    type: attr(), 
    image: attr(), 
    bedrooms: attr() 
}); 

應用程序/海市蜃樓/ config.js

export default function() { 
    this.get('/rentals', function() { 
    return { 
     data: [{ 
     type: 'rentals', 
     id: 1, 
     attributes: { 
      title: 'Grand Old Mansion', 
      owner: 'Veruca Salt', 
      city: 'San Francisco', 
      type: 'Estate', 
      bedrooms: 15, 
      image: 'https://upload.wikimedia.org/wikipedia/commons/c/cb/Crane_estate_(5).jpg' 
     } 
     }, { 
     type: 'rentals', 
     id: 2, 
     attributes: { 
      title: 'Urban Living', 
      owner: 'Mike Teavee', 
      city: 'Seattle', 
      type: 'Condo', 
      bedrooms: 1, 
      image: 'https://upload.wikimedia.org/wikipedia/commons/0/0e/Alfonso_13_Highrise_Tegucigalpa.jpg' 
     } 
     }, { 
     type: 'rentals', 
     id: 3, 
     attributes: { 
      title: 'Downtown Charm', 
      owner: 'Violet Beauregarde', 
      city: 'Portland', 
      type: 'Apartment', 
      bedrooms: 3, 
      image: 'https://upload.wikimedia.org/wikipedia/commons/f/f7/Wheeldon_Apartment_Building_-_Portland_Oregon.jpg' 
     } 
     }] 
    }; 
    }); 
} 

應用程序/路由/ index.js

import Ember from 'ember'; 

    export default Ember.Route.extend({ 
     model() { 
     return this.store.findALL('rental'); 
     } 
    }); 

應用/模板/ index.hbs

<h3>Welcome to Super Rentals</h3> 

<p> 
    We are dedicated to helping you! 
</p> 

{{#each model as |rental|}} 
    <h2>{{rental.title}}</h2> 
    <p>Owner: {{rental.owner}}</p> 
    <p>Type: {{rental.type}}</p> 
    <p>Location: {{rental.city}}</p> 
    <p>Number of Bedrooms: {{rental.bedrooms}}</p> 
{{/each}} 

{{#link-to "about"}}About Us!{{/link-to}} 
{{#link-to "contact"}}Contact Us!{{/link-to}} 


{{outlet}} 

Note--的ember.js指南是稍顯落伍與Ember的當前版本的,所以我還使用these edits的餘燼數據。 md文件。

回答

2

那麼,它的store.findAll不是store.findALL! Javascript是區分大小寫的。

+0

謝謝!哈哈他們的方式我的監視器顯示這是有點誤導。 –

+0

其實不是。 'store.findALL'是'undefined',這不是一個函數,所以你不能調用它。 – Lux

相關問題