0
如何根據分配的ID打印數組的表達式?我有兩個數組,其中一個的ID爲11,另一個爲12.如何獲得數組的名稱表達式,其屬性爲12?Angular Js:如何根據ID在數組中選擇表達式?
下面是服務模塊,控制器和HTML
http://jsfiddle.net/ADukg/4705/
var myApp = angular.module('myApp',[]);
function MyCtrl($scope, myProperties) {
$scope.name = 'StackOverflow';
$scope.myProperties = myProperties;
};
myApp.factory('myProperties', function() {
var myProperties = [
{
'name': '3 Bedroom Fixer Upper',
'city': 'Santa Rosa',
'id': 11,
'state': 'CA',
'date_added': '2/3/14',
'completion_status': '80%',
'imgURL': 'http://dfon12yb6dcdf.cloudfront.net/product/kr4f0uv5tkd6slvmn7r9j4h4jj/w1024x683.jpg?v=4',
},
{
'name': '2 Bedroom Condo',
'city': 'Vallejo',
'id': 12,
'state': 'CA',
'date_added': '4/10/20',
'completion_status': '50%',
'imgURL': 'http://dfon12yb6dcdf.cloudfront.net/product/kr4f0uv5tkd6slvmn7r9j4h4jj/w1024x683.jpg?v=4',
},
]
//return the array here
return myProperties
});
<div ng-controller="MyCtrl">
<h1>Hello, {{name}}!</h1>
<br>
<ul ng-repeat="property in myProperties">
<li>{{property.name}}</li>
</ul>
<br>
<h3>{{property.id[12]}}</h3>
</div>