jquery - Backbone Model Save with Specific Attributes, How to Post some attrs when syncing? -
i've got new model tons of attributes. when #save
ing expect backbone #post
because id null, works correctly.
$ = require('jquery') - = require('underscore') model = new backbone.model({ id: null, name: "tom", cat: false, dog: true, //... many more attrs whiskers: false, tail: true });
now want send small subset of attributes server on post.
with jquery can write this:
data = _.pick(model.attributes, 'name', 'dog', 'tail'); $.post(model.url(), data);
how can backbone?
i did sync below, felt wrong.
data = {} data.attrs = _.pick(model.attributes, 'name', 'dog', 'tail'); model.sync('create', model, data)
Comments
Post a Comment