I have a REST service that provides me with a list in .JSON format like the one shown below:
[{"name":"Temperature","id":32,"description":"Temperature on desk","lastModifier":"admin","lastModification":"2013-07-17"},
{"name":"Presence","id":34,"description":"maDescription2","lastModifier":"admin","lastModification":"2014-01-14"}]
My goal is to display this list in a table using three attributes: name, description, and lastModification.
I've tried the following solutions:
However, I am having trouble understanding...
This is my code:
The model:
var sensors = Backbone.Model.extend({
defaults: {
name: "",
id:"",
description:"",
lastModifier:"",
lastModification:""
},
});
The collection:
var SensorsCollection = Backbone.Collection.extend({
model: sensors,
url:'../../rest/groups'
});
The view:
var SensorsView = Backbone.View.extend({
model: new sensors(),
sensorsCollection: new SensorsCollection(),
el: $("#sensorsDiv"),
initialize: function(){
},
events:{
"click #btnAddUser": "getSensors"
},
getSensors: function(){
var tokenCookie;
var name = "xtoken" + "=";
var ca = document.cookie.split(';');
for(var i=0; i < ca.length; i++)
{
var c = ca[i].trim();
if (c.indexOf(name) == 0) tokenCookie = c.substring(name.length,c.length);
}
if(tokenCookie == undefined){
alert("Please log in!")
}else{
this.sensorsCollection.fetch({
headers: {"X-Token": tokenCookie},
statusCode:{
202: function(){
}
}}
);
}
}
});
var sensorsView = new SensorsView();