Answer the question
In order to leave comments, you need to log in
How to search in Angular for related objects in the form of their url?
There are 2 models
Tickets
[
{
"id": 1,
"client_url": "http://127.0.0.1:8000/api/v1/clients/1/",
"url": "http://127.0.0.1:8000/api/v1/tickets/1/"
},
{
"id": 2,
"client_url": "http://127.0.0.1:8000/api/v1/clients/2/",
"url": "http://127.0.0.1:8000/api/v1/tickets/2/"
},
{
"id": 3,
"client_url": "http://127.0.0.1:8000/api/v1/clients/2/",
"url": "http://127.0.0.1:8000/api/v1/tickets/3/"
}
]
[
{
"id": 1,
"full_name": "Петров Иван Сергеевич",
"birthdate": "1992-04-22",
"url": "http://127.0.0.1:8000/api/v1/clients/1/"
},
{
"id": 1,
"full_name": "Иванов Иван Иванович",
"birthdate": "1992-04-21",
"url": "http://127.0.0.1:8000/api/v1/clients/2/"
}
]
Answer the question
In order to leave comments, you need to log in
var clientUrls = _(clients).filter(function(i){
return i.full_name.indexOf('Петров')>=0;
})
.map(function(i){
return i.url;
}).value();
var myTickets = _.filter(tickets, function(t){
return _.some(clientUrls, function(i){return i===t.client_url;});
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question