我得到了服务REST,它给了我一个这样的.JSON列表:
[{"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"}]
我想使用3个attributs名称,description和lastModification在表格中显示此列表。
我试试这些解决方案:
http://liquidmedia.org/blog/2011/02/backbone-js-part-3/
但我只是不明白...... 这是我的代码:
模特:
var sensors = Backbone.Model.extend({
defaults: {
name: "",
id:"",
description:"",
lastModifier:"",
lastModification:""
},
});
收藏:
var SensorsCollection = Backbone.Collection.extend({
model: sensors,
url:'../../rest/groups'
});
观点:
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("veuillez vous connecter !")
}else{
this.sensorsCollection.fetch({
headers:{"X-Token":tokenCookie},
statusCode:{
202: function(){
}
}}
);
}
}
});
var sensorsView = new SensorsView();