Update README.md

This commit is contained in:
Joe Vu 2014-03-18 13:15:35 -07:00
parent 89379b527d
commit fab16122b4

View File

@ -15,10 +15,15 @@ model.save([file attribute], [file object], [options]);
model.set('file', [file object]); model.set('file', [file object]);
model.save({}, [options]) model.save({}, [options])
``` ```
### save & set ### set & save
#### model.save( [file attribute], [file object], [options] )
#### model.set( [file attribute], [file object], [options] ) #### model.set( [file attribute], [file object], [options] )
In terms of how to use these methods, they have not changed. The only difference is that it has the capability to take a File object grabbed from the DOM (i.e. `<input type="file" />`). As the file is being uploaded, a trigger `progress` fires as the browser sends chunks of data. The `progress` trigger sends a progress status in percents. #### model.save( [file attribute], [file object], [options] )
In terms of how to use these methods, they have not changed. The only difference is that it has the capability to take a File object grabbed from the DOM (i.e. `<input type="file" />`).
As the file is being uploaded, a trigger `progress` fires as the browser sends chunks of data. The `progress` trigger sends a progress status in percents.
If you want to force not using FormData, add the option `{ formData: false }` and the whether or not you have a file object in the model, it'll try to send it as part of the JSON object. Opposite is true (for whichever circumstance) is that if you set `{ formData: true }`, it will force the usage of FormData. Not setting it will leave it automatic and it'll try to detect if there is the file in the model.
```js ```js
var fileObject = $(':input[type="file"]')[0].files[0]; var fileObject = $(':input[type="file"]')[0].files[0];
@ -69,7 +74,7 @@ var obj = {
} }
} }
``` ```
Will return: Will parse into
``` ```
obj['family'] => 'The Smiths'; obj['family'] => 'The Smiths';
obj['grandpa.name'] => 'Ole Joe Smith'; obj['grandpa.name'] => 'Ole Joe Smith';