Cannot use 'in' operator to search for '18' in canjs

188 views Asked by At

I am calling ajax function for getting data from model. I am trying to load the data in template but i cannot setting the attributes in can.list. Here is my call:

this.domainModel.getDomains("domains", function (response, error) {
  if ('domains' in response) {
                   self.filteredList.attr("domains",list);
    } else {
        return error;
    }
})

It showing Cannot use 'in' operator to search for '18'. I search for this in google but I found the results for jquery. Is there any other options?

1

There are 1 answers

1
jfriend00 On BEST ANSWER

The Javascript in operator searches for a specific property name on a Javascript object. That's what it does.

It doesn't search an array for a value in the array. It doesn't search an object for a property with a given value. Either of these uses would be coded differently.

It is not clear in your code what type of data structure you are trying to search for 18 in so we cannot really advise further how to solve your specific problem without more detail.

Here's how in works:

var test = {
    greeting: "hello",
    name: "john"
};

if ("greeting" in test) {
    console.log("found greeting property in test object");
}