locked
using a where clause on inner Array in linq.min.js libary RRS feed

  • Question

  • User-2097295820 posted

    I am using ajax to return a json to javascript. I collect content from my database and store in my csharp object which I later convert to json.

     public class Dispatchagentinfo
        {
            public int ID { get; set; }
    
            public string Fullname { get; set; }
    
            public string Phone { get; set; }
    
            public string Agenttype { get; set; }
    
            public int NoofAssigneddelivery { get; set; }
    
            public List<int> LGAID { get; set; }  //This is the LGA that this agent is assigned to
    
            public List<int> StateID { get; set; }
        }

    I want to do a where clause on my javascrpt function using the StateID in the were clause but it not working. I would paste my javascript module below

    function Getagentinstate(stateid) {
        
        var queryResult = Enumerable.From(agentlist)
            .Where(function (x) { return x.StateID.indexOf(stateid) != -1 }) //My problem is here. How do I check the array content
      .Select(function (x) { return x; }).ToArray();
    
        //console.log("list of query result " + queryResult.length);
        return queryResult;
    }

    How can I use the array in my were clause using linq.min.js

    Monday, September 10, 2018 11:50 PM

Answers

  • User-2097295820 posted

    Thanks, unfortunately it did not work. So I added a new variable to the c sharp object which is a string variable.

    public string StateIDs{ get;set; }

    Then I use the indexOf method in the javascript to check inside the where clause and it works like magic. Instead of the continous stress.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, September 14, 2018 7:00 PM

All replies

  • User839733648 posted

    Hi skliz4rel,

    According to your description and code, I suggest that you could use the function .Contains() to find the result you want.

    You could try the code below.

    var queryResult = Enumerable.From(agentlist)
      .Where(function (x) { Enumerable.From(x.StateID).Contains(stateid) }) 
      .Select(function (x) { return x; }).ToArray();
    

    Best Regards,

    Jenifer

    Wednesday, September 12, 2018 11:06 AM
  • User-2097295820 posted

    Thanks, unfortunately it did not work. So I added a new variable to the c sharp object which is a string variable.

    public string StateIDs{ get;set; }

    Then I use the indexOf method in the javascript to check inside the where clause and it works like magic. Instead of the continous stress.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, September 14, 2018 7:00 PM