1

Emberアプリケーションを使用してWordPressアプリケーションからデータをフェッチしようとしています。私は '2'のIDでWordPressのメニュー項目を取得しようとしています。私はember-wordpressプラグインを使用していて、投稿を正常に取得できます。私はAPIからメニューを取得するのに苦労しています。ヌルエバーのプロパティ 'id'を読み取ることができません

以下はここに私のルートである私のメニュー・モデル

import DS from 'ember-data'; 

export default DS.Model.extend({ 
    name: DS.attr('string'), 
    count: DS.attr('number') 
}); 

です。

import Ember from 'ember'; 

export default Ember.Route.extend({ 

    model() { 
    return Ember.RSVP.hash({ 
     menu: this.store.findRecord('menu', 2) 
    }); 
    } 

}); 

私はURLをヒットしようとすると、しかし、私はここに私のコンソールに

Error while processing route: Cannot read property 'id' of null TypeError: Cannot read property 'id' of null

をエラーが発生しますが、私は私のエンドポイントから取得していJSONです。

{ 
"ID": 2, 
"name": "Main Menu", 
"slug": "main-menu", 
"description": "", 
"count": 2, 
"items": [ 
{ 
"id": 19, 
"order": 1, 
"parent": 0, 
"title": "Projects", 
"url": "http://localhost:8888/ember-wp/projects/", 
"attr": "", 
"target": "", 
"classes": "", 
"xfn": "", 
"description": "", 
"object_id": 17, 
"object": "page", 
"object_slug": "projects", 
"type": "post_type", 
"type_label": "Page" 
}, 
{ 
"id": 20, 
"order": 2, 
"parent": 0, 
"title": "Services", 
"url": "http://localhost:8888/ember-wp/services/", 
"attr": "", 
"target": "", 
"classes": "", 
"xfn": "", 
"description": "", 
"object_id": 15, 
"object": "page", 
"object_slug": "services", 
"type": "post_type", 
"type_label": "Page" 
} 
], 
"meta": { 
"links": { 
"collection": "http://localhost:8888/ember-wp/wp-json/wp/v2/menus/", 
"self": "http://localhost:8888/ember-wp/wp-json/wp/v2/menus/2" 
} 
} 
} 

ここでどこが間違っているのか誰にでも見られますか?

答えて

1

同じ問題が発生したため、WP API Menusプラグインを使用してデータをプルダウンすると想像します。これを修正するには、そのプラグインのファイルの1つを編集する必要があります。ライン108上の

  1. は、あなたの問題を解決する小文字に大文字からこれらの2つのキーを変更$rest_menu['ID'] = abs($menu['term_id']);から$rest_menu['id'] = abs($menu['term_id']);

を、ライン143上$rest_menus[ $i ]['id'] = $menu['term_id'];

  • $rest_menus[ $i ]['ID'] = $menu['term_id'];を変更する変更wp-api-menus-v2.php

    ... 。

  • 1

    私はあなたが得るエラーについてはわかりませんが、最初の要素には 'id'フィールドがなく、 'ID'フィールド(大文字)があります。

    関連する問題