骨幹(以及相當多的.js)新手。試圖在客戶端學習MVC架構。嘗試在頁面加載時填充骨幹網集合
的目標是重新創建的jQuery功能
$.getJSON('/application/listsurveys', function(data) {
$.each(data.surveys,function(i,item) {
$('#surveyListTable').append('<tr onMouseover="onMouseOverHandler()" onMouseout="onMouseOutHandler()" >'
+ '<td id="testData">'+ item.title + '<br>ID ' + item.surveyId + '</td>'
+ '<td>' + new Date(item.uploadDate).toLocaleDateString() + '</td>'
+ '<td>' + item.ndgUser.username + '</td>'
+ '<td><a href="">' + item.resultCollection.length + '</a></td>'
+ '<td width=250><img src="images/back.jpg" id=Tools></td>'
+ '</tr>');
});
});
,但我不能讓過去的JSON加載 - 我有什麼到目前爲止,這是
var Survey = Backbone.Model.extend({
initialize: function(){
console.log("A single survey model was created");
}
});
var SurveyList = Backbone.Collection.extend({
initialize: function(){
console.log("A survey collection was created");
},
url :'/application/listsurveys',
model: Survey
});
var App = {
init: function() {
var surveys = new SurveyList({});
surveys.fetch({success: loadApp});
}
};
// kick off the application
$(document).ready(function() {
App.init();
});
它給出了一個不能調用AJAX方法未定義的骨幹錯誤。我讀了
訪存不應該用於在頁面加載時填充集合 - 加載時需要的所有模型應該已經被引導到位。
所以我想硬編碼在模型創建的JSON像
var App = {
init: function() {
var survey = new Survey({"surveys":[{"available":1,"id":1,"ndgUser":{"username":"admin"},"resultCollection":[],"surveyId":"1263929563","title":"Demo Survey","uploadDate":1311603000000}]});
var surveyObject = survey.get('surveys');
available = surveyObject[0].available;
alert(available);
}
};
這會提醒預期的結果1.如何從此處移動並在頁面加載時拉出此JSON?