Tôi là người mới trong Backbone. Vì vậy, tôi đang cố gắng lấy dữ liệu từ dịch vụ REST.Backbone.js + Rest. Bộ sưu tập không được điền sau khi tìm nạp()
đây là mã đơn giản của tôi:
$(function() {
var Entity = Backbone.Model.extend({
url: function() {
return 'http://localhost:8080/rest/entity/'+this.id;
}
});
var EntityList = Backbone.Collection.extend({
model: Entity,
url: 'http://localhost:8080/rest/entity'
});
var entityList = new EntityList();
entityList.fetch();
});
dịch vụ của tôi trở về nghỉ ngơi JSON tiếp theo:
[{"id":1387,
"version":3,
"entityName":"entity01",
"entityLabel":"Entity01",
"entityPluralLabel":"Entity01",
"attributes":
[{"id":1425,
"slot":"D001",
"version":0,
"attributeName":"dfield",
"attributeType":
{"id":7,
"description":"Date",
"attributeType":"date",
"databaseType":"DATE"
},
"options":[],
"order":2,
"attributeLabel":"dField",
"checked":null
},
{"id":1424,
"slot":"S001",
"version":0,
"attributeName":"txfield",
"attributeType":
{"id":1,
"description":"Textbox",
"attributeType":"textbox",
"databaseType":"STRING"
},
"options":[],
"order":1,
"attributeLabel":"txField",
"checked":null
}
]
},
{"id":1426,
"version":3,
"entityName":"entity02",
"entityLabel":"Entity02",
"entityPluralLabel":"Entity02",
"attributes":
[{"id":1464,
"slot":"D001",
"version":0,
"attributeName":"dfield",
"attributeType":
{"id":7,
"description":"Date",
"attributeType":"date",
"databaseType":"DATE"
},
"options":[],
"order":2,
"attributeLabel":"dField",
"checked":null
}
]
}
]
Trong debugger tôi thấy yêu cầu đó đã được gửi đến dịch vụ REST và phản ứng đã nhận được, thế nào tôi có thể xem liệu bộ sưu tập entityList có được thu thập dữ liệu nhận được hay không? Trong thực thể debuggerList.models rỗng sau entityList.fetch();
Tôi đang đi đúng cách hay có vấn đề gì với mã của tôi?
xương sống được khá đơn giản. Có lẽ nó giúp chỉ cần bước qua nguồn xương sống thực tế để xem những gì đang xảy ra. – Evert