加載JSON數據我一直在關注燼快速入門指南創建顯示一些數據的應用程序(https://guides.emberjs.com/v2.13.0/getting-started/quick-start/),而是顯示只是科學家的名字JavaScript數組的,我想展示的產品來自以下json。灰燼應用程序無法從本地文件
我已經把JSON文件中的公用文件夾。
它看起來像:
{
"products": [
{
"_id": "58ff60ffcd082f040072305a",
"slug": "apple-tree-printed-linen-butterfly-bow-tie",
"name": "Apple Tree Printed Linen Butterfly Bow Tie ",
"description": "This fun 40 Colori Apple Tree Printed Linen Butterfly Bow Tie features a design of various apple trees built from tiny polka dots. The back of this bow tie features a polka dot print in complementing colours which when the bow tie is tied will pop out from behind making for a subtle yet unique detail. The playful design, stand out natural linen texture, and colourful combinations make this bow tie a perfect accessory for any outfit!\n",
"standard_manufacturer": "58cbafc55491430300c422ff",
"details": "Size: Untied (self-tie) bow tie with an easily adjustable neck strap from 13-3/4'' to 19'' (35 to 48 cm)\nHeight: 6 cm\nMaterial: Printed 100% linen\nCare: Dry clean\nMade in Italy",
"sizes": [
{
"value": "Violet",
"size": "57722c80c8595b0300a11e61",
"_id": "58ff60ffcd082f0400723070",
"marked_as_oos_at": null,
"quantity": -1,
"stock": true,
"id": "58ff60ffcd082f0400723070"
},
等。
我對路線的模型顯示列表代碼如下
import Ember from 'ember';
export default Ember.Route.extend({
model() {
//return ['Marie Curie', 'Mae Jemison', 'Albert Hofmann'];
return Ember.$.getJSON("/products.json");
}
});
我已經完全按照教程除了在scientists.js的
return Ember.$.getJSON("/products.json");
線。我的數據沒有被顯示,並且我在餘燼檢查員中得到的錯誤是
compiled.js:2 Uncaught TypeError: Failed to execute 'getComputedStyle' on 'Window': parameter 1 is not of type 'Element'.
at E (compiled.js:2)
at Object.u (compiled.js:25)
at compiled.js:25
E @ compiled.js:2
u @ compiled.js:25
(anonymous) @ compiled.js:25
我是非常新的燼並且與js相當新。任何幫助感謝!謝謝!
所有的「故事」的數據爲這個應用程序我建立了從應用程序目錄中的靜態文件加載/所以我知道這是可能的是這樣的工作。 http://judge.justicefor.us/ – sheriffderek
你可能必須重新格式化JSON是灰燼友好 – sheriffderek
您的意思是線路2:從「你的應用程序內/ JSON-文件name.json」 進口yourData – Yiannis