OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

JS .some return not correct result

  • Thread starter Thread starter Eugene Sukh
  • Start date Start date
E

Eugene Sukh

Guest
I have function that must returns class name related on condition

Here is function

Code:
  function getScheduleTruckDispatchStatusClass(truck) {
        if (truck.dispatches === undefined || truck.dispatches === 0) {
            return 'schedule-dispatch-status-inactive';
        }
        if (truck.dispatches.some(x => x.status === abp.enums.dispatchStatus.created || abp.enums.dispatchStatus.sent)) {
            return 'schedule-dispatch-status-lgreen';
        }
        if (truck.dispatches.some(x => x.status === abp.enums.dispatchStatus.acknowledged || abp.enums.dispatchStatus.loaded)) {
            return 'schedule-dispatch-status-dgreen';
        }
        if (truck.dispatches.some(x => x.status === abp.enums.dispatchStatus.completed)) {
            return 'schedule-dispatch-status-active';
        }
        if (truck.dispatches.some(x => x.status === abp.enums.dispatchStatus.cancelled)){
            return 'schedule-dispatch-status-hidden';
        }
        return '';
    }

enum of statuses is like this

Code:
  abp.enums.dispatchStatus = {
    created: 0,
    sent: 1,
    acknowledged: 3,
    loaded: 4,
    completed: 5,
    error: 6,
    canceled: 7
};

in response from back end I see this status

enter image description here

So it must go to this block

Code:
  if (truck.dispatches.some(x => x.status === abp.enums.dispatchStatus.acknowledged || abp.enums.dispatchStatus.loaded)) {
            return 'schedule-dispatch-status-dgreen';
        }

But it always go to this one

Code:
 if (truck.dispatches.some(x => x.status === abp.enums.dispatchStatus.created || abp.enums.dispatchStatus.sent)) {
            return 'schedule-dispatch-status-lgreen';
        }

How I can fix this?

<p>I have function that must returns class name related on condition</p>
<p>Here is function</p>
<pre><code> function getScheduleTruckDispatchStatusClass(truck) {
if (truck.dispatches === undefined || truck.dispatches === 0) {
return 'schedule-dispatch-status-inactive';
}
if (truck.dispatches.some(x => x.status === abp.enums.dispatchStatus.created || abp.enums.dispatchStatus.sent)) {
return 'schedule-dispatch-status-lgreen';
}
if (truck.dispatches.some(x => x.status === abp.enums.dispatchStatus.acknowledged || abp.enums.dispatchStatus.loaded)) {
return 'schedule-dispatch-status-dgreen';
}
if (truck.dispatches.some(x => x.status === abp.enums.dispatchStatus.completed)) {
return 'schedule-dispatch-status-active';
}
if (truck.dispatches.some(x => x.status === abp.enums.dispatchStatus.cancelled)){
return 'schedule-dispatch-status-hidden';
}
return '';
}
</code></pre>
<p>enum of statuses is like this</p>
<pre><code> abp.enums.dispatchStatus = {
created: 0,
sent: 1,
acknowledged: 3,
loaded: 4,
completed: 5,
error: 6,
canceled: 7
};
</code></pre>
<p>in response from back end I see this status</p>
<p><a href="https://i.sstatic.net/AxILNq8J.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/AxILNq8J.png" alt="enter image description here" /></a></p>
<p>So it must go to this block</p>
<pre><code> if (truck.dispatches.some(x => x.status === abp.enums.dispatchStatus.acknowledged || abp.enums.dispatchStatus.loaded)) {
return 'schedule-dispatch-status-dgreen';
}
</code></pre>
<p>But it always go to this one</p>
<pre><code> if (truck.dispatches.some(x => x.status === abp.enums.dispatchStatus.created || abp.enums.dispatchStatus.sent)) {
return 'schedule-dispatch-status-lgreen';
}
</code></pre>
<p>How I can fix this?</p>
 

Latest posts

A
Replies
0
Views
1
Aarif Hussain A Nassar
A
F
Replies
0
Views
1
Fahmi Nur Fachrurozi
F
Top