问题描述:

I've got a new model with tons of attributes.

When #saveing i expect backbone to #POST because the ID is null, this 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 I want to only send a small subset of attributes to the server on that POST.

With jquery i can write this:

data = _.pick(model.attributes, 'name', 'dog', 'tail');

$.post(model.url(), data);

How can I do this with Backbone?

I did it with sync below, but it felt wrong.

data = {}

data.attrs = _.pick(model.attributes, 'name', 'dog', 'tail');

model.sync('create', model, data)

相关阅读:
Top