I have a simple backbone app that fetches a collection from a JSON file which works fine. But I really want to fetch a single modal from the collection. Ideally I want to fetch the model using the locale attribute.
How can I do this?
So far I have the following code,
var Item = Backbone.Model.extend({
defaults:{
"locale":"",
"name":"",
}
});
var ItemsCollection = Backbone.Collection.extend({
model: Item,
url: 'data/items.json'
});
var items = new ItemsCollection();
var itemView = new ItemView({model: items});
items.fetch({
success: function() {
itemView.render();
}
})
Json structure is this,
[
{
"locale": "gb",
"name": "British"
},
{
"locale": "de",
"name": "German"
}
]
Thanks