【发布时间】:2013-12-23 17:32:17
【问题描述】:
我正在尝试这个问题中建议的解决方案,但它不起作用
How to pass parameters to a view
How can I pass a parameter into a Backbone.js view?
Backbone.js - passing arguments through constructors
我正在尝试传递额外参数以在我的模板中使用,我读到我传递的所有额外参数我都可以在this.options.varName 中访问它们,但它对我不起作用。
这里是控制器代码:
servicios : function(){
//Crea la colecion de tipos de servicios municipales
//Crea el modelo para dar de alta un nuevo reporte de servicio municipal
var reporteServicioSingle = new ReporteServicioSingle();
//Crea la vista para la pantalla de servicios municipales
var servicios_view = new Servicios({
model : reporteServicioSingle,
collection : this.reportes,
tipos : this.tipos
});
// Carga la vista renderisada y inicializa foundation
$("#app-content").html(servicios_view.render().el);
$(document).foundation();
},
这是我的视图代码:
render: function(){
console.log(this.options.tipos);
this.$el.html(Handlebars.templates.servicios(this.collection));
$(document).foundation();
return this;
},
但是 chrome 开发者控制台,给我一个选项未定义的错误。
Uncaught TypeError: Cannot read property 'tipos' of undefined
谢谢你,对不起我的英语不好。
【问题讨论】: