2017-11-06 8 views
1

イオン3の新機能ですが、ボタンをクリックすると新しいページがプッシュされ、JSONデータがHTMLに表示されます。各ボタンはIDで識別したいので、そのIDに関連するデータだけを表示します。例えばIonic 3 Json Dataで新しいページを開く

-

ユーザーButton1をクリック - >ボタン1のみID 1

に次にDATASを表示する参照画面に移行する別のボタン(ボタン2)に関係するデータを表示する画面を参照に進みますそれだけで(などなど)のid 2に関し、関係

マイコード:

私levels.htmlファイルで

私levels.tsで10
<button id="levels-button5" on-click="goToReference()"> 
    <ion-icon name="button1"></ion-icon> 
    Button 1 
    </button> 

goToReference(params){ 
    if (!params) params = {}; 
    this.navCtrl.push(ReferencePage); 
    } 

referenceList = []; 


//Calling the data from the API and storing it in referenceList[] 
getReferences() { 
    this.servicesProvider.getReferences().subscribe(data => this.referenceList = data); 
} 

ファイルI []はreferenceList =へのREST APIからJSONデータを格納しています。配列から、説明、コンテンツ、画像を表示したいと思います。どんな助けでも大歓迎です!

+0

あなたが持っているjsonデータは配列に格納されていますか? –

+0

はい - 私は、REST APIからデータを取得し、referenceList = []配列に格納しました – cdh429

答えて

0
goToReference(params) 
{ 
    if (!params) params = {}; 
    this.navCtrl.push(ReferencePage); 
} 

ReferencePage

let data = this.navParams.get("data"); 
+0

すごく試してみましょう!御時間ありがとうございます! – cdh429

0

でデータをフェッチしながら、私はあなたがこの

​​

と.TSには、それが動作を期待

getReferences(idx:number) { 

    // here you can access your list data by index 
    // when button is pressed the index of that perticular button is accessible here 
    // and from that you pass the data as per your need 

    this.servicesProvider.getReferences().subscribe(data => this.referenceList = data); 
} 

ファイルのように行う必要があると思いますあなたのために !!

+0

これを試してみてください....ありがとうございました:) – cdh429

+0

また、(クリック) - "getReferences(i)"を置くことを意味しましたか?今すぐTSファイル – cdh429

+0

で作業しています。このgetReferences(i)メソッドをhtmlファイルに入れると、このmathodもtsファイルに書き込む必要があります。使用しているときは、インデックスがTSファイルで利用可能です –

関連する問題