在我的示例中,我需要按项目分组,然后按天显示数据。
请参阅http://jsfiddle.net/3M7QD/2/
我想显示如下:
项目 1 SundayHours MondayHours ...
项目 2 SundayHours MondayHours ...
var json = [
{
"HOURS": 0,
"PROJECT_NAME": "Project 1",
"DATE_WORKED": "/Date(1353225600000)/"
},
{
"HOURS": 0,
"PROJECT_NAME": "Project 2",
"DATE_WORKED": "/Date(1353225600000)/"
},
{
"HOURS": 8.5,
"PROJECT_NAME": "Project 1",
"DATE_WORKED": "/Date(1353312000000)/"
},
{
"HOURS": 0,
"PROJECT_NAME": "Project 2",
"DATE_WORKED": "/Date(1353312000000)/"
},
{
"HOURS": 8,
"PROJECT_NAME": "Project 1",
"DATE_WORKED": "/Date(1353398400000)/"
},
{
"HOURS": 0,
"PROJECT_NAME": "Project 2",
"DATE_WORKED": "/Date(1353398400000)/"
},
{
"HOURS": 8.5,
"PROJECT_NAME": "Project 1",
"DATE_WORKED": "/Date(1353484800000)/"
},
{
"HOURS": 0,
"PROJECT_NAME": "Project 2",
"DATE_WORKED": "/Date(1353484800000)/"
},
{
"HOURS": 4,
"PROJECT_NAME": "Project 1",
"DATE_WORKED": "/Date(1353571200000)/"
},
{
"HOURS": 4,
"PROJECT_NAME": "Project 2",
"DATE_WORKED": "/Date(1353571200000)/"
},
{
"HOURS": 4,
"PROJECT_NAME": "Project 1",
"DATE_WORKED": "/Date(1353657600000)/"
},
{
"HOURS": 4,
"PROJECT_NAME": "Project 2",
"DATE_WORKED": "/Date(1353657600000)/"
},
{
"HOURS": 0,
"PROJECT_NAME": "Project 1",
"DATE_WORKED": "/Date(1353744000000)/"
},
{
"HOURS": 0,
"PROJECT_NAME": "Project 2",
"DATE_WORKED": "/Date(1353744000000)/"
}
];
var Project = function(data){
this.PROJECT_NAME = ko.observable(data.PROJECT_NAME);
this.HOURS = ko.observable(data.HOURS);
};
var ProjectRowItem = function(data){
this.PROJECT_NAME = ko.observable(data.PROJECT_NAME);
this.SundayProjectEntry = new Project(data);
this.MondayProjectEntry = new Project(data);
this.TuesdayProjectEntry = new Project(data);
this.WednesdayProjectEntry = new Project(data);
this.ThursdayProjectEntry = new Project(data);
this.FridayProjectEntry = new Project(data);
this.SaturdayProjectEntry = new Project(data);
};
var viewModel = {
Projects : ko.observableArray(ko.utils.arrayMap(json, function(item){
return new ProjectRowItem(item);
})),
NewProjectName : ko.observable()
};
viewModel.addRow = function()
{
var data = {
PROJECT_NAME : viewModel.NewProjectName(),
HOURS : "0"
};
viewModel.Projects.push(new ProjectRowItem(data));
}
viewModel.removeRow = function(project)
{
viewModel.Projects.remove(project);
}
ko.applyBindings(viewModel);
</p>
编辑 1 - 我想做的是按项目对数据进行分组,然后在列中显示该项目的每个数组项。