2017-01-04 6 views
-2

私はスプリングブート角度jsを使ってアプリケーションを開発しています。ここでは、json配列とjsonオブジェクトを扱い、異常ツリーを使ってツリーを構築しています。キーを使用して別のjson配列内のjson配列を取得する

細かく構築するツリー。このツリーは各ノードをクリックすると更新されるため、データベースからロードすることによりクリック時と同じようにランタイム時に子供が追加されます。

ツリーJSONのようなものです:

[{"parent":"Title-1","expanded":true,"label":"Title-1","children":[ 
    {"parent":"Title-1","expanded":true,"label":"Chapter-I", "children":[ 
     {"parent":"Chapter-I","expanded":false,"children":[],"label":"Part-1"},{"parent":"Chapter-I","expanded":false,"children":[],"label":"Part-10"},{"parent":"Chapter-I","expanded":false,"children":[],"label":"Part-100"},{"parent":"Chapter-I","expanded":false,"children":[],"label":"Part-11"},{"parent":"Chapter-I","expanded":false,"children":[],"label":"Part-12"},{"parent":"Chapter-I","expanded":false,"children":[],"label":"Part-13"},{"parent":"Chapter-I","expanded":false,"children":[],"label":"Part-14"},{"parent":"Chapter-I","expanded":false,"children":[],"label":"Part-140"},{"parent":"Chapter-I","expanded":false,"children":[],"label":"Part-49"},{"parent":"Chapter-I","expanded":false,"children":[],"label":"Part-5"},{"parent":"Chapter-I","expanded":false,"children":[],"label":"Part-50"},{"parent":"Chapter-I","expanded":false,"children":[],"label":"Part-7"},{"parent":"Chapter-I","expanded":false,"children":[],"label":"Part-75"},{"parent":"Chapter-I","expanded":false,"children":[],"label":"Part-8"},{"parent":"Chapter-I","expanded":false,"children":[],"label":"Part-9"}]}, 
    {"parent":"Title-1","expanded":true,"label":"Chapter-II","children":[ 
     {"parent":"Chapter-II","expanded":false,"children":[],"label":"Part-200"},{"parent":"Chapter-II","expanded":false,"children":[],"label":"Part-201"},{"parent":"Chapter-II","expanded":false,"children":[],"label":"Part-202"},{"parent":"Chapter-II","expanded":false,"children":[],"label":"Part-203"},{"parent":"Chapter-II","expanded":false,"children":[],"label":"Part-204"},{"parent":"Chapter-II","expanded":false,"children":[],"label":"Part-205"},{"parent":"Chapter-II","expanded":false,"children":[],"label":"Part-209"},{"parent":"Chapter-II","expanded":false,"children":[],"label":"Part-210"},{"parent":"Chapter-II","expanded":false,"children":[],"label":"Part-211"},{"parent":"Chapter-II","expanded":false,"children":[],"label":"Part-285"},{"parent":"Chapter-II","expanded":false,"children":[],"label":"Part-286"},{"parent":"Chapter-II","expanded":false,"children":[],"label":"Part-287"},{"parent":"Chapter-II","expanded":false,"children":[],"label":"Part-288"},{"parent":"Chapter-II","expanded":false,"children":[],"label":"Part-289"},{"parent":"Chapter-II","expanded":false,"children":[],"label":"Part-290"},{"parent":"Chapter-II","expanded":false,"children":[],"label":"Part-300"},{"parent":"Chapter-II","expanded":false,"children":[],"label":"Part-301"}]}] 
}] 

上記は、UIに戻り、ツリーが表示されたので、私は、JSファイル内のコードを避けるために、バックエンドのリソースクラスにこのJSONを構築しています。

このjsonは、PartのそれぞれがSubpart/Subgroupsなどを追加するにつれて、さらに成長します。次のsubpartは、その子を追加します。したがって、part..subpartのChildrenは、子をロードするオブジェクトを追加します。

このjsonのトラバースは大きくなりつつあります。ループも増加しています。与えられた文字列のjsonarrayにループを張らずに子を追加する簡単な方法はありますか?

私はPart-200の子供が欲しいのですが、私はちょうどノードの名前を提供し、ループと繰り返しなしでPart-200のjson配列を取得しますか?

答えて

0

できるだけシンプルなJSONデータを作成してください。 APIから応答を受け取ったときに巨大になるかもしれません。 JSONを単純化し、ビュー・レベルに入る前にスコープ変数にそれらを格納するいくつかの関数を記述してください。 ng-repeatのようなループでは複雑になります。毎回loopsに行くことを望まないかもしれません。したがって、ビューに表示される必要なすべてのデータが、ビューから簡単にアクセスできるようにスコープ変数に含める必要があります。

+0

完全なjsonはUIに戻りスコープ変数に格納されます。私はJava側で問題が発生している、何もuiのJavaスクリプトの角度側で行う必要があります、それは単にリソースのJavaクラスから返されたデータを表示する必要があります。私はそのノードでノードを取得して子ノードで更新できるようにしたい。 –

関連する問題