afeld/backbone-nested

change event not triggered when setting an object that contains an array

Open

#131 ouverte le 5 mars 2015

Voir sur GitHub
 (4 commentaires) (0 réactions) (0 assignés)JavaScript (83 forks)github user discovery
Bughelp wanted

Métriques du dépôt

Stars
 (439 stars)
Métriques de merge PR
 (Aucune PR mergée en 30 j)

Description

var model = new Backbone.NestedModel({
    a: {
        b: [
            { c: 1 },
            { d: 2 }
        ]
    }
});

model.bind('change:a.b[0].c', function() { console.log('c changed.'); });

// The following set triggers the change event:
model.set('a.b[0].c', 3);

// The following does not trigger the change event:
model.set({
    a: {
        b: [
            { c: 4 },
            { d: 2 }
        ]
    }
});

But this works as expected sans array:

var model2 = new Backbone.NestedModel({
    a: {
        b: { 
            c: 1
        }
    }
});

model2.bind('change:a.b.c', function() { console.log('c changed.'); });

// The following set triggers the change event:
model2.set({
    a: {
        b: {
            c: 12
        }
    }
});

Guide contributeur