I'm diving into Backbone for the first time and I'm facing difficulties making it work smoothly with a JSON data file.
Here's how my model looks:
window.Test = Backbone.Model.extend({
defaults: {
id: null,
name: null,
},
url: function() {
return 'json/test.json/this.id';
},
initialize: function(){
}
});
When I click on a test item, I attempt to display the details of the specific model that was clicked by using:
testDetails: function (id) {
var test = new Test();
test.id = id;
test.fetch({ success: function(data) { alert(JSON.stringify(data))}});
},
However, this doesn't seem to work as expected. I am struggling to fetch the JSON element with the passed ID accurately.
Could someone please guide me on how to properly structure the model's URL in order to retrieve the element with the ID?
Thank you!