TypeError:无效的"in"操作数n [英] TypeError: invalid 'in' operand n
问题描述
在萤火虫中,我遇到了一个错误,它告诉我在underscore.min.js中是类型错误
In the firebug, I have got an error, it told me that it's a type error in the underscore.min.js
当我推荐month.js中的错误行时,没有错
when I commended out the error line in the month.js, there is nothing wrong
我不知道自己犯了什么错误,已经检查了monthCollection,并确定monthCollection是正确的
I don't know what mistake I have made, I have checked the monthCollection and I'm sure the monthCollection is right
我无法访问DayView的初始化,日志没有成功",而只有一行开始创建新的日视图"
I couldn't access the initialize of DayView, the log has no 'success' but just one line 'begin to new a day view'
js/views/month.js
js/views/month.js
define([
'backbone',
'underscore',
'views/day'
], function(Backbone, _, DayView) {
'use strict';
var MonthView = Backbone.View.extend({
initialize: function(el, collection) {
this.el = el;
this.monthCollection = collection;
this.render();
},
//draw the month
render: function() {
this.monthCollection.each(function(date) {
var tmpDate = date.get("date");
var tmpDay = date.get("day");
console.log("begin to new a day view");
var dayView = new DayView(tmpDate, tmpDay); //error
// this.el.append(dayView.view);
}, this);
}
});
return MonthView;
});
js/views/day.js
js/views/day.js
define([
'backbone',
'underscore'
], function(Backbone, _) {
'use strict';
var DayView = Backbone.View.extend({
dateTemplate: _.template( $('#date-template').html() ),
initialize: function(date, day) {
console.log("success");
this.date = date;
switch(day) {
case 0:
this.day = Sun;
break;
case 1:
this.day = Mon;
break;
case 2:
this.day = Tue;
break;
case 3:
this.day = Wen;
break;
case 4:
this.day = Thu;
break;
case 5:
this.day = Fri;
break;
case 6:
this.day = Sat;
break;
default:
this.day = fail;
}
this.render();
},
//draw the day to this.view
render: function() {
this.view = this.dateTemplate({
date: this.date,
day: this.day
});
}
});
return DayView;
});
推荐答案
这个错误曾经发生在我身上,因为我将参数作为字符串而不是作为对象传递给视图.
This error once happened to me because I passed the parameter to the view as a string instead as a object.
这篇关于TypeError:无效的"in"操作数n的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!