[英]Using JSON Api URL EmberJS
我通常從我創建的服務(即硬編碼JSON)中獲取數據。 但是我需要從URL中獲取JSON。
這是我的玩笑:
如何添加URL作為源,而不是從“圖片”服務中調用它? 我嘗試了一些操作,但遇到錯誤,無法執行任何操作。 我對此很陌生。
我試過了
model() {
return $.getJSON('/my-url');
}
但是我得到這個錯誤:
Mirage: Your Ember app tried to GET 'my URL', but there was no route defined to handle this request. Define a route that matches this path in your mirage/config.js file. Did you forget to add your namespace?
我完全不知道該錯誤,因為我不使用海市rage樓,是的,但是我沒有在項目的任何部分中使用它。
然后我嘗試了:
import Ember from 'ember';
export default Ember.Route.extend({
model() {
this.get('my Json url', () => {
return [];
});
}
});
現在chrome的devTool沒有給出任何錯誤,但是我看到的只是空白頁。 這是全部錯誤還是.hbs
文件的問題?
有什么想法嗎?
卸載ember-cli-mirage
並返回到:
model() {
return $.getJSON('/my-url');
}
通過一些幫助,我發現了問題所在:
解:
在我的index.js中,我應該使用
{{image-list model=model.Data currentPos=currentPos }}
代替
{{image-list model=model currentPos=currentPos }}
另外,我不需要任何model/*.js
。js,因為我從IndexRoute獲得了model()
,所以我刪除了那些文件。 謝謝
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.