作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 View 中添加了一个模型属性,如下所示:
app.ActorView = Backbone.View.extend({
modelImg:'', ....
我跳到渲染部分,因为其他一切都正常:
render: function () {this.$el.html(this.template({
modImg: this.modelImg.toJSON(),
mod: this.model.toJSON(),
movies: this.collection.toJSON()}
View 中的每个模型(模型、集合和 modelimg)都在我的项目的 rooter 部分中正确获取:
modActor.fetch().done(function () {
modActorMovies.fetch().done(function () {
modImgActor.fetch().done(function () {
var actorView = new app.ActorView({
modelImg: modImgActor,<--problematic model
model: modActor,
collection: modActorMovies
});
我的 modImgActor 定义如下:
app.ActorImg= Backbone.Model.extend({
url: "http://umovie.herokuapp.com/unsecure/actors/272994458/movies",
parse: function (response) {
return response.results[0];
}
});
问题是当我在 modelImg 上使用 toJson() 函数时。出现以下错误:this.modelImg.toJSON 不是函数
模型是如何用它的 url 定义的吗?
最佳答案
modImg
不是 Backbone.View
的标准选项。所以 Backbone 会忽略它。
您必须手动处理与选项一起传递的自定义属性。
所以你的 View 定义应该是
app.ActorView = Backbone.View.extend({
initialize: function(options){
this.modelImg = options.modelImg;
}
}):
关于javascript - 模型渲染内 View : toJSON is not a function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33589000/
我是一名优秀的程序员,十分优秀!