I have the following object:
lstMsg = {
"count": 6,
"next": null,
"previous": null,
"results": [{
"id": 3,
"sender": 2,
"receiver": {
"id": 4,
"username": "ghazan",
"first_name": "ghazan",
"last_name": "ghazan"
},
"title": "salam",
"body": "reza khoobi",
"created_time": "20-6-1394 15:42:34.647251"
},
{
"id": 2,
"sender": 2,
"receiver": {
"id": 4,
"username": "ghazan",
"first_name": "ghazan",
"last_name": "ghazan"
},
"title": "reis",
"body": "salam reis",
"created_time": "20-6-1394 15:41:49.512305"
},
{
"id": 1,
"sender": 2,
"receiver": {
"id": 4,
"username": "ghazan",
"first_name": "ghazan",
"last_name": "ghazan"
},
"title": "shaftan",
"body": "saalam",
"created_time": "20-6-1394 15:41:38.626508"
}
]
}
I'm trying to find a specific item (i.e item with id = 2) and I'm using filter in javascript:
showMessage = function(msg_id) {
var found = $filter('filter')(lstMsg.results, {
id: msg_id
}, true);
result = found[0];
message = result.body;
title = result.title;
}
But it always returns the first item, no matter which id I'm looking for.
I'm wondering where am I doing wrong?
found