将模型的 属性 传递给 ItemView 中的模板
Pass a property of the model to the template in ItemView
我想将我的模型的 属性 传递给模板,所以我想我需要一个 serializeData 函数,我试过这个
serializeData:function(){
return this.model.toJSON().extend({_schema:this.model.schema});
}
但它抱怨无法扩展 toJSON 的输出。这一定是一个标准技巧,将原型中的一些值粘贴到序列化形式中,以便模板可以使用它。
在此用例中使用 templateHelpers
– serializeData
更适合完全替换模型属性,或缩小它们的范围。
templateHelpers: function()
{
return { _schema: this.model.schema };
}
Harladson 的答案是最好的,但如果其他人看起来不同,您可以这样做:
serializeData:function(){
var data = this.model.toJSON();
data._schema = this.model.schema;
return data;
}
我想将我的模型的 属性 传递给模板,所以我想我需要一个 serializeData 函数,我试过这个
serializeData:function(){
return this.model.toJSON().extend({_schema:this.model.schema});
}
但它抱怨无法扩展 toJSON 的输出。这一定是一个标准技巧,将原型中的一些值粘贴到序列化形式中,以便模板可以使用它。
在此用例中使用 templateHelpers
– serializeData
更适合完全替换模型属性,或缩小它们的范围。
templateHelpers: function()
{
return { _schema: this.model.schema };
}
Harladson 的答案是最好的,但如果其他人看起来不同,您可以这样做:
serializeData:function(){
var data = this.model.toJSON();
data._schema = this.model.schema;
return data;
}