如何在angular2中键入数组值

时间:2017-05-13 05:36:05

标签: javascript typescript

enter image description here
我有一个如图所示的数组,当用户点击first_name时,必须对名字的值进行排序。如果用户点击电子邮件,则必须对电子邮件的值进行排序

 ResultData =[{"First_name":"Raju","Phone":"9533993043","countryCode":"+91","order_datetime":"2017-5-3 11:13:49","status":14,"DeviceType":3,"orderId":"59096e3c320b2103820d855b","orderseqId":"E00002389","orderType":1,"CustomerID":"5908b6f6ee5df65f70fcdd81","pickAddress":"1-62/6, Gachibowli - Miyapur Rd, Laxmi Cyber City, Prashanth Nagar Colony, Kothaguda, Hyderabad, Telangana 500084, India","dropAddress":"1-`2/1/24/A/1,7,plot no 17, Hitech City Main Rd, Khanamet, Madhapur, Hyderabad, Telangana 500081,` India","pickLatitude":17.4566454,"pickLongitude":78.36482890000002,"dropLatitude":17.4535075,"dropLongitude":78.38307110000005,"paymentType":2,"itemDescription":"","receiverName":"Raju","receiverPhone":"9533993043","itemName":"Computer","deliverycharge":"199","bookingType":1}]

当我使用下面的方法时,我只能通过First_name键获取排序数组

sortObject(obj) {
    var arr = [];
    for (var prop in obj) {
        if (obj.hasOwnProperty(prop)) {
            arr.push({
                'key': prop,
                'value': obj[prop]
            });
        }
    }
    arr.sort(function(a, b) { return a.value - b.value; });
    return arr; // returns array
}

但我希望通过传递密钥和对象来排序值..任何plunker它都会帮助我..

  

注意:我没有在我的阵列中获得相同的密钥

如果我将First_name作为密钥传递 那么first_name键的值必须排序.. 如果我将pickAddress作为键传递,则必须对pickAddress的值进行排序。

0 个答案:

没有答案