0

私の例では、プロジェクトごとにグループ化し、データを日ごとに表示する必要があります。

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>

EDIT 1 - 私がやりたいのは、データをプロジェクトごとにグループ化し、そのプロジェクトの各配列項目を列に表示することです。

4

0 に答える 0