gpt4 book ai didi

javascript - 获取 TypeError : this. options is undefined

转载 作者:行者123 更新时间:2023-11-30 06:53:44 25 4
gpt4 key购买 nike

我正在尝试学习 BackboneJS,这是我遇到的错误。

我正在用 coffeescript 编码,这是生成的 JS 我不知道为什么会这样,因为我认为我做的是正确的。

(function() {
var AppRouter, MenuItemDetails, app;

MenuItemDetails = Backbone.View.extend({
render: function() {
var markup;
markup = "<div>" + this.options.category + "</div>";
this.$el.html(markup);
return this;
}
});

AppRouter = Backbone.Router.extend({
routes: {
"": "list",
"menu-items/new": "itemForm",
"menu-items/:item": "itemDetails"
},
list: function() {
return $('#app').html('List Screen');
},
itemDetails: function(item) {
var view;
view = new MenuItemDetails({
name: item,
category: 'Entree',
imagepath: 'no-image.jpg'
});
return $('#app').html(view.render().el);
},
itemForm: function() {
return $('#app').html("New item form");
}
});

app = new AppRouter();

Backbone.history.start();

}).call(this);

/*
//@ sourceMappingURL=app.map
*/

我哪里错了?

最佳答案

尝试这样做:

  MenuItemDetails = Backbone.View.extend({
initialize: function(options) {
this.options = options;
},
render: function() {
var markup;
markup = "<div>" + this.options.category + "</div>";
this.$el.html(markup);
return this;
}
});

关于javascript - 获取 TypeError : this. options is undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21738333/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com