문제

usersCollection.fetch({
    success: function () {
        var getModel = usersCollection.where(checkIDJSON);
        //update that partcular attribute
        getModel.set('interest', 'rolling stones');
        console.log("Users:" + usersCollection.toJSON());

    },
    error: function () {
        // something is wrong..
    }

});

After running the code, it complains that the function is undefined, when trying to save to the model. Any idea why? thanks

I am using backbone.js in titanium mobile

도움이 되었습니까?

해결책

From the fine manual:

where collection.where(attributes)

Return an array of all the models in a collection that match the passed attributes.

So when you say this:

var getModel = usersCollection.where(checkIDJSON);

you end up with an array of models in getModel. If you're sure that there will only be one model that matches, then use findWhere:

findWhere collection.findWhere(attributes)

Just like where, but directly returns only the first model in the collection that matches the passed attributes.

like this:

var getModel = usersCollection.findWhere(checkIDJSON);

If there could be multiple matches then presumably you'd want to call set on each one.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top