Javascript Parse.com-Parse.Object.extend(…)属性

Javascript Parse.com-Parse.Object.extend(…)属性,javascript,parse-platform,underscore.js,Javascript,Parse Platform,Underscore.js,我正在使用Parse JS和主干网,并尝试打印Parse JS模型中的值列表。这很简单,但我对objectId有问题 那么,我有 var Thing = Parse.Object.extend('MyThings'); var Things = Parse.Collection.extend({ model: Thing }); var collection = new Things(); collection.fetch({ success: function(){

我正在使用Parse JS和主干网,并尝试打印Parse JS模型中的值列表。这很简单,但我对objectId有问题

那么,我有

var Thing = Parse.Object.extend('MyThings');
var Things = Parse.Collection.extend({
    model: Thing
});

var collection = new Things();
collection.fetch({
    success: function(){
        App.start(collection.toJSON());
    }
});
这是我的看法

ThingView = Backbone.View.extend({
    tagName: 'tr',
    render: function(){
        this.$el.html(_.template($('#item-template').html(), this.model.attributes));
    }
});

ThingListView = Backbone.View.extend({
    tagName: 'table',
    addAll: function(){
        this.collection.forEach(this.addOne, this);
    },
    render: function(){
        this.$el.empty();
        this.addAll();
    },
    addOne: function(item){
        var itemView = new ThingView({model: item});
        itemView.render();
        this.$el.append(itemView.el);
    }
});
这是一个模板(带有下划线.js)


属性名称和颜色显示正确,但“id未定义”


有什么想法吗?

问题是id不存在于属性中。它实际上位于对象的根。因此,您需要做的是将this.model而不是this.model.attributes传递到u.template()中,然后在HTML中进行相应调整,例如:

render: function(){
    this.$el.html(_.template($('#item-template').html(), this.model));
}

<td><%= id %></td>
<td><%= attributes.name %></td>
<td><%= attributes.color %></td>
render:function(){
this.el.html(35;.template($('#item template').html(),this.model));
}

视图在哪里?是否设置了idAttributes?#项模板封装在(标记名:“tr”)中。Name和color是属性,但id是由Parse指定的objectId。这两个属性都正确显示,但在控制台中显示的“ReferenceError:id未定义”中,我没有看到对
id
属性的任何引用。你确定你说的不是
cid
?谢谢!我已经用另一种方法解决了,但是你的解决方案更好。我很好奇,你采用的另一种解决方案是什么?添加一个属性id:this.model.attributes.id=this.model.id;
render: function(){
    this.$el.html(_.template($('#item-template').html(), this.model));
}

<td><%= id %></td>
<td><%= attributes.name %></td>
<td><%= attributes.color %></td>