Problem reference variable in the Collections.where method inside the render function

I am having problems with a piece of trunk code. The code below refers to the rendering function. I can get all the models. My problem arises when I try to use the “Collections.where” method in line number # 1. As you can see, I passed the object literal to the rendering function, but for some reason I cannot reference it in the customers method. where on line # 1. When I give this method a literal number, for example 45, it works. Is there any way around this so that I can pass the variable reference to?

Thank you so much

render: function(options) {

    var that = this;
    if (options.id) {

        var customers = new Customers();
        customers.fetch({
            success: function (customers) {
   /* #1 --> */ var musketeers = customers.where({musketeerId: options.id});
                console.log(musketeers.length) //doesn't work as options.id is failing on last line
                var template = _.template($('#customer-list-template').html(), {
                    customers: customers.models
                });
                that.$el.html(template);
                console.log(customers.models);
            }
        });

    } else {
        var template = _.template($('#customer-list-template').html(), {});
        that.$el.html(template);
    }
}
0
source share
1 answer

, Collection#where strict (===) . :

where: function(attrs, first) {
  if (_.isEmpty(attrs)) return first ? void 0 : [];
  return this[first ? 'find' : 'filter'](function(model) {
    for (var key in attrs) {
      if (attrs[key] !== model.get(key)) return false;
    }
    return true;
  });
},

attrs[key] !== model.get(key) , 10 ( id) '10' ( , <input>), . , :

customers.where({musketeerId: 10});

-,

customers.where({musketeerId: '10'});

.

parseInt:

// Way off where you extract values from the `<input>`...
options.id = parseInt($input.val(), 10);
+2

All Articles