AngularJS $ http.get结果到数组

时间:2017-08-03 13:30:49

标签: javascript angularjs

我使用$ http.get来获取包含MailID和SubscribedDate的数据。 结果分配给$ scope.subscriber。我希望拥有所有MailID值的数组,例如:["john@msn.com","peter@gmail.com", "mike@stack.com"]



	getAll();
	function getAll() {
		var servCall = APIService.getSubs();
		servCall.then(function (d) {
			$scope.subscriber = d;
		}, function (error) {
			console.log('Oops! Something went wrong while fetching the data.')
		});




2 个答案:

答案 0 :(得分:0)

使用javascript map函数获取电子邮件ID

servCall.then(function(d) {
    $scope.mailIDarr= d.data.map(o=>o.MailID);
}, function(error) {
    console.log('Oops! Something went wrong while fetching the data.')
});

答案 1 :(得分:0)



<ArrayOftbl_Subscribers xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/WebAPIAndAngular.Models">
<tbl_Subscribers>
<MailID>first value second value third value</MailID>
<SubscribedDate>2017-08-01T16:44:06.391</SubscribedDate>
</tbl_Subscribers>
<tbl_Subscribers>
<MailID>third value fourth value sixth value</MailID>
<SubscribedDate>2017-08-01T16:48:38.977</SubscribedDate>
</tbl_Subscribers>
<tbl_Subscribers>
<MailID>kurma</MailID>
<SubscribedDate>2017-08-01T19:55:04.355</SubscribedDate>
</tbl_Subscribers>
<tbl_Subscribers>
<MailID>belekas</MailID>
<SubscribedDate>2017-08-02T05:41:32.472</SubscribedDate>
</tbl_Subscribers>
<tbl_Subscribers>
<MailID>rerere</MailID>
<SubscribedDate>2017-08-02T05:45:06.672</SubscribedDate>
</tbl_Subscribers>
<tbl_Subscribers>
<MailID>fsdfsd</MailID>
<SubscribedDate>2017-08-02T05:45:41.483</SubscribedDate>
</tbl_Subscribers>
<tbl_Subscribers>
<MailID>1111</MailID>
<SubscribedDate>2017-08-02T06:33:37.331</SubscribedDate>
</tbl_Subscribers>
</ArrayOftbl_Subscribers>
&#13;
&#13;
&#13;