I have a scenario where the data being manipulated on the client is presented and interacted with in a different way than it is represented on the server.
Consider the following event resource returned from the server.
{
"id": 123,
"start_at": 1331336004906,
"end_at": 1331337704906
}
And the following template for editing:
<form>
<!-- Notice how date and time are separated in the interface -->
<input type="text" name="start_date" value="{{start_date}}" />
<input type="text" name="start_time" value="{{start_time}}" />
<!-- Instead of asking for an end date/time, we ask for the duration -->
<input type="text" name="duration" value="{{duration}}" />
<input type="submit" />
</form>
How would I go about treating start_date, start_time, and duration as attributes in my Backbone model without sending them to the server? Am I supposed to modify .toJSON()?
Your model should correspond as closely as possible to what you have server side. So stick with
start_atandend_at. That will greatly simplify yoursync()operations.On your edit form’s View, you can:
start_date,start_time,durationthrough simple functions and call them in the template.start_atandend_aton submitting.