backbone.picky icon indicating copy to clipboard operation
backbone.picky copied to clipboard

Attribute vs member

Open paultyng opened this issue 12 years ago • 1 comments

The docs for this seem to say it will change a "selected" attribute on the model but it seems to only set a member on that instance instead of in the attributes collection via set.

On Backbone.Picky.Selectable:

    select: function () {
      if (this.selected) { return; }

      **this.selected = true;**
      this.trigger("selected");

      if (this.collection) {
        this.collection.select(this);
      }
    },

Is this intentional? I have to override my view serialization to render to pass this every time, so seems undesirable, but maybe I'm missing something?

Is this so that a change event isn't also fired or something? I guess on a fetch you would lose the selection state as well, but that could be handled.

paultyng avatar Jun 09 '13 14:06 paultyng

it seems that this is by design. it might also be a bit much of an assumption to make, that the model is automatically selected for anybody who loads it.

perhaps you can just subscribe to the 'select' event to set an attribute on the model, and on fetch or reset of the model, trigger the relevant select on the collection.

AdrianRossouw avatar Sep 12 '13 17:09 AdrianRossouw