-
-
Save mtthwkfmn/187831 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
var store = $.cloudkit; | |
store.boot({ | |
// booting the store reads the metadata on the server, | |
// loads existing data, and configures the local store | |
// for use | |
success: function() { | |
// the local store is now ready | |
// create a 'thing' | |
store.collection('things').create({name:"box"}, { | |
success: function(thing) { | |
// the 'thing' resource has now been created | |
// locally and posted to the server | |
alert(thing.json().name); // this will display "box" | |
// update the 'thing' | |
thing.update({name:"book"} { | |
success: function() { | |
// the updated 'thing' resource has been mirrored | |
// on the server and is ready for use again | |
alert(thing.json().name); // this is now "book" | |
// delete the 'thing' | |
thing.destroy({ | |
success: function() { | |
// the 'thing' has now been deleted | |
} | |
} | |
} | |
}) | |
} | |
}); | |
// create a 'note' | |
store.collection('notes').create({foo:"bar"}, { | |
success: function(note) { | |
// do something with the note | |
} | |
}); | |
// find all 'note' resources | |
var notes = store.collection('notes').all(); | |
// get a specific note | |
var note = store.collection('notes').get(some_random_note.id()); | |
// find all things having a name of 'book' | |
var matches = store.collection('things').query("?name='book'"); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment