我想使用创建日历AngularJS
,我的模型是这样的对象:
$scope.model = {
weeks: [
{
days: [
null,
{
name: "3 dec",
toDoItems: [{ name: "Task 1" }, { name: "Task 2"}]
},
{
name: "4 dec",
toDoItems: [{name: "Task 1"}, {name: "Task 2"}]
}
]
},
{
days: [
null,
{
name: "5 dec",
toDoItems: [{ name: "Task 1" }, { name: "Task 2"}]
},
{
name: "6 dec",
toDoItems: [{name: "Task 1"}, {name: "Task 2"}]
}
]
}
]
}
但我想动态创建对象。
我试过这样的事情,但它给了我以下错误:
TypeError: Cannot call method 'push' of undefined
$scope.fillMonth = function () {
var gap = dayInWeek($scope.year.value, $scope.month, 1),
nrOfDays = daysInMonth($scope.year.value, $scope.month);
$scope.model = {};
for (var i = 0; i < (nrOfDays + gap) % 7; i++) {
for (var j = 0; j < 7; j++) {
if (j === 0)
$scope.model.weeks.push([]);
if (i === 0 && j < gap)
$scope.model.weeks[i].days.push(null);
else
$scope.model.weeks[i].days.push([{ name: i + ' ' + j, toDoItems: [{ name: "Task 1" }, { name: "Task 2"}]}]);
}
}
}
谁能帮我这个?提前致谢!