Hey there, I have a JSON object named "Faults" that looks like this:
"Faults":[{"RoomId":1,"ElementId":173,"FaultTypeId":1,"Count":1,"Remark":""},{"RoomId":3,"ElementId":211,"FaultTypeId":7,"Count":1,"Remark":""},{"RoomId":4,"ElementId":173,"FaultTypeId":1,"Count":1,"Remark":""}]
When I check the Faults object in the debugger, it shows up like this:
https://i.sstatic.net/30GJA.png
Now, my task is to determine if a room contains a Fault by using its RoomId
.
The code I'm currently using for this purpose is as follows:
Enumerable.From(audit.Rooms).ForEach(function(room, index) {//√
var containsFaults = '';
//room.Id always has a value and cannot be null
var test1 = faults.Select("$.RoomId==" + room.Id).Count();
var test2 = faults.Select("$.RoomId==" + room.Id);
if (faults.Select("$.RoomId==" + room.Id).Count() > 0) {
containsFaults = '√';
}
However, when I run this code, the results are not as expected...
https://i.sstatic.net/91zFH.png
I'm puzzled why it's not returning the faults from my object with matching RoomId
. The Id's definitely match. Can anyone point out what mistake I might be making here? I'm really stuck on this issue...
Appreciate any help you can provide!