2016-12-21 2 views
1

私はAngular/Ionicを初めて使用しており、短い質問があります。 2つのオブジェクトを1つのスコープに入れることは可能ですか?このように:AngularJS&Ionic:1つのスコープに2つのオブジェクト?

$scope.Lorem = [ 
    { title: 'Ipsum', 
     text: 'Lorem ipsum dolor sit amet consetetur sadipscing elitr', 
     cards: [{ 
       title_cards: 'Title1', 
       desc_cards: 'desc1', 
      }, 
      { 
       title_cards: 'Title2', 
       desc_cards: 'desc3', 
      } 
     ]}, 
     ]; 

「はい」の場合:「カード」からデータを取得するにはどうすればよいですか?そうでない場合:スコープとオブジェクトを別のスコープから「接続」する可能性はありますか?

私を助けることができますように!ありがとう。

+0

スコープには大きなオブジェクトが1つしか表示されません。ただし、同じスコープ上に2つの異なるオブジェクトを持つことができます。 –

+1

@CédricDourinあなたは望むどんなjsonオブジェクトもスコープ変数に入れることができます。 1つのjsonオブジェクト内に、他のjsonオブジェクトを入れ子にすることができます。 '$ scope.Lorem'にあるものは**配列**です。 – Hosar

答えて

0

$ scope.Lorem.cards [x]。*を使用してカードを取得できます。ここで、xはアクセスするオブジェクトのインデックスで、*はアクセスするキーです。

0

以下のあなたがHTMLで通常のオブジェクトと同様に

jsの中$scope.Lorem[0].cards[0].title_cardsLorem[0].cards[0].title_cardsにアクセスすることができますあなたの条件

<!DOCTYPE html> 
 
<html ng-app="plunker"> 
 

 
    <head> 
 
    <meta charset="utf-8" /> 
 
    <title>AngularJS Plunker</title> 
 
    <script>document.write('<base href="' + document.location + '" />');</script> 
 
    <link rel="stylesheet" href="style.css" /> 
 
    <script data-require="[email protected]" src="https://code.angularjs.org/1.4.12/angular.js" data-semver="1.4.9"></script> 
 
    <script src="app.js"></script> 
 
    </head> 
 

 
    <body ng-controller="MainCtrl"> 
 
    <div>{{Lorem[0].title}}</div> 
 
    <div>{{Lorem[0].text}}</div> 
 
    <div ng-repeat="x in Lorem[0].cards"> 
 
    <p>{{x.title_cards}}</p> 
 
    <p>{{x.desc_cards}}</p> 
 
    </div> 
 
    </body> 
 
<script> 
 
    var app = angular.module('plunker', []); 
 

 
app.controller('MainCtrl', function($scope) { 
 
    $scope.name = 'World'; 
 
    $scope.Lorem = [ 
 
    { title: 'Ipsum', 
 
     text: 'Lorem ipsum dolor sit amet consetetur sadipscing elitr', 
 
     cards: [{ 
 
       title_cards: 'Title1', 
 
       desc_cards: 'desc1', 
 
      }, 
 
      { 
 
       title_cards: 'Title2', 
 
       desc_cards: 'desc3', 
 
      } 
 
     ]}, 
 
     ]; 
 
     
 
}); 
 
</script> 
 
</html>

+0

万人に感謝!!!!!それはうまくいった! –

+0

ようこそ........ –

0

であることを願って。

関連する問題