Skip to content

Instantly share code, notes, and snippets.

@amundo
Created September 9, 2012 19:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amundo/3686675 to your computer and use it in GitHub Desktop.
Save amundo/3686675 to your computer and use it in GitHub Desktop.
trying to make a nested collection
window.show = function(o){ return JSON.stringify(o, null,2)}
app = {};
app.Word = Backbone.Model.extend({
})
app.Words = Backbone.Collection.extend({
model: app.Word,
localStorage : new Backbone.LocalStorage('srsly_words')
})
app.Sentence = Backbone.Model.extend({
initialize: function(){
this.set({'words': new app.Words});
},
url : 'js/sentence_data.js',
parse: function(response){
this.get('words').reset(response.words);
return response;
}
})
app.Text = Backbone.Collection.extend({
model: app.Sentence,
localStorage : new Backbone.LocalStorage('srsly_text'),
})
$(function(){
app.sentence = new app.Sentence();
})
{
"transcription": "hinispleʔ eč ašup, siyamš aʔoʔ",
"translation": "When this world perished, it was full of water",
"words": [
{ "morphemes" : "hini-s-pleʔ", "gloss" : "when-3RD-SG-to.perish" },
{ "morphemes" : "eč", "gloss" : "this" },
{ "morphemes" : "ašup", "gloss" : "world" },
{ "morphemes" : "s-iyam-š", "gloss" : "3RD.SG-to.be.full-INTR" },
{ "morphemes" : "aʔoʔ", "gloss" : "water" }
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment