我正在構建一個網頁以顯示基於分析的應用程序的所有用戶最近的捐贈。我從這裏找到的示例Todo應用程序構建此應用程序:https://parse.com/tutorials/todo-app-with-javascript。這裏是我的主.js文件的代碼(這主要是反映了教程todo.js比替換類名和其他等):完整的分析對象不可用於下劃線模板
//Donation Model
//--------------
var Donation = Parse.Object.extend("Donation", {
//instance methods
//Default attributes
defaults: {
},
//Ensure that each donation created has content
initialize: function() {
}
});
// This is the transient application state, not persisted on Parse
var AppState = Parse.Object.extend("AppState", {
defaults: {
filter: "all"
}
});
//Donation Collection
//-------------------
var DonationList = Parse.Collection.extend({
model: Donation
});
//Donation Item View
//-----------------
var DonationView = Parse.View.extend({
tagName: "tr",
template: _.template($('#donation-template').html()),
//The DOM events specific to donation
events: {
},
initialize: function() {
_.bindAll(this, 'render');
this.model.bind('change', this.render);
},
render: function() {
$(this.el).html(this.template(this.model.toJSON()));
return this;
}
});
//The Application
//---------------
var AdminView = Parse.View.extend({
el: ".content",
initialize: function() {
var self = this;
_.bindAll(this, 'addOne', 'addAll', 'render');
this.$el.html(_.template($('#admin-template').html()));
////create out collection of donations
this.donations = new DonationList;
//setup the Parse query
var query = new Parse.Query(Donation);
query.include("user");
query.include("charity");
query.include("business");
this.donations.query = query;
this.donations.bind('add', this.addOne);
this.donations.bind('reset', this.addAll);
this.donations.bind('all', this.render);
this.donations.fetch({
success: function(donations) {
for(var i = 0; i < donations.length;i++) {
console.warn(donations.models[i]);
}
}
});
state.on("change", this.filter, this);
},
render: function() {
this.delegateEvents();
},
filter: function() {
this.addAll();
},
addOne: function(donation) {
var view = new DonationView({model: donation});
this.$("#donation-list").append(view.render().el);
},
addAll: function(collection, filter) {
this.$('#donation-list').html("");
this.donations.each(this.addOne);
}
});
//The main view for the app
var AppView = Parse.View.extend({
// Instead of generating a new element, bind to the existing skeleton of
//the App already present in the HTML.
el: $("#adminapp"),
initialize: function() {
this.render();
},
render: function() {
new AdminView();
}
});
var state = new AppState;
new AppView;
當模特被取出從parse在
this.donations.fetch({
success: function(donations) {
for(var i = 0; i < donations.length;i++) {
console.warn(donations.models[i]);
}
}
});
我完全掌握了捐贈中的所有指針關係,例如用戶及其所有屬性,慈善機構及其所有屬性等。但是,我有興趣顯示捐贈用戶的用戶名下劃線模板,但在此時,捐贈用戶對象不再具有用戶名屬性。就好像某些屬性在查詢返回時和爲新模板提供新捐款集之間被刪除一樣。這裏有下劃線的模板:
<script type="text/template" id="donation-template">
<td><%= donationAmount %></td>
<td><%= charity %></td>
<td><%= user %></td>
<td><%= business %></td>
<td><%= createdAt %></td>
</script>
donationAmount和createdAt按預期顯示,但慈善機構,用戶和業務都只是顯示爲[Object對象],我不能用點號訪問他們的任何屬性。我怎樣才能確保我需要的所有這些指針關係的屬性都可以被下劃線視圖使用?
閱讀解析JS SDK文檔如何填充指針和關係。他們不是默認填充 – charlietfl 2015-01-20 18:33:02
不包括應該完成這個?如果我將它們記錄在查詢的成功塊中,我可以看到所有的對象屬性,但之後它們似乎不可用。 – mike 2015-01-20 18:42:49