2016-05-26 7 views
0

私はMongoDBの中のオブジェクトのこのスキーマを持っていると、オブジェクトの配列を格納しない、私はこの質問に私のオブジェクトCARを呼び出します:どのように私はangularJS

this.carroSchema = new Schema({ 
    modelo: String, 
    ano: String, 
    placa: String, 
    cor: String, 
    categoria: [{tipo: String, preco: String}], 
    createdOn: {type: Date, default: Date.now} 
}); 

とiは物体CARを取得し、この機能を持っています私はこのような選択を行う場合は、配列に格納 'arrayCarros' が

$scope.carregarCarros = function(){ 
    $http({ 
     method: 'GET', 
     url: '/listaCarro' 
    }) 
    .then(function successCallback(response){ 
     $scope.arrayCarros = response.data; 
    }, function errorCallback(response){ 
     alert(response.data); 
    }); 
} 

<select class="form-control" ng-click = "carregarCarros()" name="select"> 
<option ng-repeat = "carros in arrayCarros">{{carros.placa}}</option>      
</select> 

私が交流を持っていますオブジェクトCARからプロパティー 'プラカード'に行きます。そのため、私は選択した値を表示することができます。

しかし、私の質問は、どのように私のオブジェクトCARの内側にある配列 'categoria'を他の配列に格納すればいいのですか?私のオプションで彼のng-repeatを行い、 「tipo」と「preco」?

答えて

0

これは簡単な方法です。もちろん、Array.filterやArray.reduceのようなjavascript関数をユースケースに応じて使うことができますが、以下は簡単な解決策です。

$scope.other_array = []; 

response.data.forEach(function(car){ 
    $scope.other_array.push(car.categoria) 
}) 

console.log(other_array) 

また、あなたが複数のNG-の反復を持っており、一つだけがcarros.categoriaをレンダリングcarros.placeと1をレンダリングすることができますに注意すべきです。つまり、両方のvarsが同じng-repeat内でレンダリングされているだけです。

+0

またはmap()を使用してください。 – charlietfl