J'ai un objet qui contient des tâches imbriquées et groupées par jour de la semaine. Je ne peux pas changer sa structure. Quelle est la manière optimale de retourner la première tâche à partir de celle où la valeur de la clé "status" de cette tâche! == "complete".Renvoie le premier objet à contenir une valeur spécifique dans un tableau d'objets imbriqués à niveaux multiples javascript
{
"total_resource_cost":"20.0",
"total_unassigned_tasks_count":0,
"tasks":[
{
"unassigned_tasks_count":0,
"resource_cost":"9.0",
"weekday":"Tuesday",
"date":"2017-07-11",
"tasks":[
{
"id":6196,
"title":null,
"category":"Guest Ready Clean",
"status":"new",
"date":"2017-07-11",
"due_date":null,
"assigned_to":{
"name":"David",
"id":2,
"mobile":"",
"teams":[
]
},
"assigned_to_2":{
"name":"David",
"id":2,
"mobile":"",
"teams":[
]
},
"assigned_to_id":2,
"assigned_to_2_id":2,
"team":null,
"description":null,
"property":{
"id":114,
"code":"WEB-1",
"lat":"51.45625339999999",
"lng":"-0.16253770000002987",
"postal_code":"SW11 6SF"
},
"list":null,
"priority":3,
"created_by":null,
"created_at":"2017-07-11T16:39:34.944Z",
"updated_at":"2017-07-14T14:08:07.082Z",
"updated_by":{
"id":2,
"name":"David",
"teams":[
]
},
"notes":null,
"trigger_rule":"Booking followed by booking.",
"obsolete":true,
"resource_cost":"3.0"
},
{
"id":6228,
"title":null,
"category":"Owner Leaving Clean",
"status":"new",
"date":"2017-07-11",
"due_date":null,
"assigned_to":{
"name":"David the Housekeeper",
"id":220,
"mobile":"",
"teams":[
]
},
"assigned_to_2":{
"name":"David",
"id":2,
"mobile":"",
"teams":[
]
},
"assigned_to_id":220,
"assigned_to_2_id":2,
"team":null,
"description":null,
"property":{
"id":245,
"code":"ROL-1",
"lat":"51.51190219999999",
"lng":"-0.03558299999997416",
"postal_code":"E14 7JA"
},
"list":null,
"priority":3,
"created_by":null,
"created_at":"2017-07-11T16:39:39.895Z",
"updated_at":"2017-07-14T14:07:58.565Z",
"updated_by":{
"id":2,
"name":"David",
"teams":[
]
},
"notes":null,
"trigger_rule":"Booking following block.",
"obsolete":true,
"resource_cost":"2.5"
},
{
"id":6207,
"title":null,
"category":"Guest Ready Clean",
"status":"new",
"date":"2017-07-11",
"due_date":null,
"assigned_to":{
"name":"David the Housekeeper",
"id":220,
"mobile":"",
"teams":[
]
},
"assigned_to_2":{
"name":"David",
"id":2,
"mobile":"",
"teams":[
]
},
"assigned_to_id":220,
"assigned_to_2_id":2,
"team":null,
"description":null,
"property":{
"id":126,
"code":"PRO-1",
"lat":"51.5375129",
"lng":"-0.042265000000043074",
"postal_code":"E9 7DS"
},
"list":null,
"priority":3,
"created_by":null,
"created_at":"2017-07-11T16:39:35.963Z",
"updated_at":"2017-07-14T14:07:54.920Z",
"updated_by":{
"id":2,
"name":"David",
"teams":[
]
},
"notes":null,
"trigger_rule":"Booking followed by booking.",
"obsolete":true,
"resource_cost":"2.0"
},
{
"id":6202,
"title":null,
"category":"Guest Ready Clean",
"status":"new",
"date":"2017-07-11",
"due_date":null,
"assigned_to":{
"name":"David",
"id":2,
"mobile":"",
"teams":[
]
},
"assigned_to_2":{
"name":"David the Housekeeper",
"id":220,
"mobile":"+",
"teams":[
]
},
"assigned_to_id":2,
"assigned_to_2_id":220,
"team":null,
"description":null,
"property":{
"id":234,
"code":"CAD-2",
"lat":"51.4924164",
"lng":"-0.16394930000001295",
"postal_code":"SW3 2PP"
},
"list":null,
"priority":3,
"created_by":null,
"created_at":"2017-07-11T16:39:35.307Z",
"updated_at":"2017-07-14T14:07:49.911Z",
"updated_by":{
"id":2,
"name":"David",
"teams":[
]
},
"notes":null,
"trigger_rule":"Booking followed by booking.",
"obsolete":true,
"resource_cost":"1.5"
}
]
},
{
"unassigned_tasks_count":0,
"resource_cost":"11.0",
"weekday":"Wednesday",
"date":"2017-07-12",
"tasks":[
{
"id":6148,
"title":null,
"category":"Guest Ready Clean",
"status":"new",
"date":"2017-07-12",
"due_date":null,
"assigned_to":{
"name":"David",
"id":2,
"mobile":"",
"teams":[
]
},
"assigned_to_2":null,
"assigned_to_id":2,
"assigned_to_2_id":null,
"team":null,
"description":null,
"property":{
"id":116,
"code":"SAR-1",
"lat":null,
"lng":null,
"postal_code":null
},
"list":null,
"priority":3,
"created_by":null,
"created_at":"2017-07-11T16:39:28.736Z",
"updated_at":"2017-07-14T15:30:15.665Z",
"updated_by":{
"id":2,
"name":"David",
"teams":[
]
},
"notes":null,
"trigger_rule":"Booking followed by booking.",
"obsolete":true,
"resource_cost":"5.5"
},
{
"id":6193,
"title":null,
"category":"Guest Ready Clean",
"status":"new",
"date":"2017-07-12",
"due_date":null,
"assigned_to":{
"name":"David",
"id":2,
"mobile":"",
"teams":[
]
},
"assigned_to_2":null,
"assigned_to_id":2,
"assigned_to_2_id":null,
"team":null,
"description":null,
"property":{
"id":216,
"code":"MAC-1",
"lat":"51.5480904",
"lng":"-0.11545330000001286",
"postal_code":"N7 8QY"
},
"list":null,
"priority":3,
"created_by":null,
"created_at":"2017-07-11T16:39:34.435Z",
"updated_at":"2017-07-14T15:30:03.989Z",
"updated_by":{
"id":2,
"name":"David",
"teams":[
]
},
"notes":null,
"trigger_rule":"A stay has ended. Unclear what the next event is.",
"obsolete":true,
"resource_cost":"3.5"
},
{
"id":6238,
"title":null,
"category":"Guest Ready Clean",
"status":"new",
"date":"2017-07-12",
"due_date":null,
"assigned_to":{
"name":"David",
"id":2,
"mobile":"",
"teams":[
]
},
"assigned_to_2":null,
"assigned_to_id":2,
"assigned_to_2_id":null,
"team":null,
"description":null,
"property":{
"id":252,
"code":"WEL-1",
"lat":"51.4853737",
"lng":"0.03197999999997592",
"postal_code":"SE7 7PH"
},
"list":null,
"priority":3,
"created_by":null,
"created_at":"2017-07-11T16:39:40.933Z",
"updated_at":"2017-07-14T15:29:53.195Z",
"updated_by":{
"id":2,
"name":"David",
"teams":[
]
},
"notes":null,
"trigger_rule":"Booking followed by booking.",
"obsolete":true,
"resource_cost":"2.0"
}
]
}
]
}
Si intérêt pourriez-vous s'il vous plaît expliquer pourquoi c'est une amélioration? La vitesse? – larpo
La vitesse est un petit facteur, car find retournera dès qu'il trouvera une correspondance, alors que le filtre traitera tout le tableau. La grande chose pour moi est que find va retourner l'objet, pas un tableau. –