Created
April 25, 2011 01:27
-
-
Save jphpsf/940046 to your computer and use it in GitHub Desktop.
storeKeyExists_example.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Does it already exists? | |
if (MyApp.MyModel.storeKeyExists('foobar')) { | |
// The key exists, so retrieve the record to update it | |
var record = MyApp.store.find(MyApp.MyModel, 'foobar'); | |
// We only need to update the sources | |
record.set('something', 'yeah'); | |
} else { | |
// Otherwise create a new record | |
var record = MyApp.store.createRecord(MyApp.MyModel, { | |
'id': 'foobar', | |
'something': 'yeah' | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment