我正在构建一个网页以显示基于分析的应用程序的所有用户最近的捐赠。我从这里找到的示例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