Freddie
Freddie

Reputation: 61

Consuming Rest Webservices in Oracle Jet

I am new in Oracle Jet. What I want to achieve, is to Consuming Rest Webservices in Oracle Jet Table.

That is my ViewModel

 function CustomerViewModel() {
     var self = this;

    self.DeptCol = ko.observable();
    self.datasource = ko.observable();

    self.serviceURL = '/hr/employees/';
    self.parseDept = function(response) {
        return {empno: response['empno'],
            DepartmentName: response['ename'],
            LocationId: response['job'],
            ManagerId: response['hiredate'],
            mgr: response['mgr'],
            sal: response['sal'],
            comm: response['comm'],
            deptno: response['deptno']};
    };
    self.Department = oj.Model.extend({
        urlRoot: self.serviceURL,
        parse: self.parseDept,
        idAttribute: 'empno'
    });

    self.myDept = new self.Department();
    self.DeptCollection = oj.Collection.extend({
        url: self.serviceURL,
        model: self.myDept
    });

    self.DeptCol(new self.DeptCollection());
}

That is my View

<table id="table" summary="Department List" aria-label="Departments Table" 
       data-bind="ojComponent:{  
   component:'ojTable',
   data:datasource,
   columns:[  
      {  
         headerText:'empno',
         field:'empno'
      },
      {  
         headerText:'ename',
         field:'DepartmentName'
      },
      {  
         headerText:'job',
         field:'LocationId'
      },
      {  
         headerText:'hiredate',
         field:'ManagerId'
      },
      {  
         headerText:'mgr',
         field:'mgr'
      },
      {  
         headerText:'sal',
         field:'sal'
      },
      {  
         headerText:'comm',
         field:'comm'
      },
      {  
         headerText:'deptno',
         field:'deptno'
      }
   ]
}"> 
</table>

When I test my Page, it doesn't show any Errors and the Page is blank. Somebody can help, please? Thanks

Upvotes: 1

Views: 1459

Answers (2)

user957654
user957654

Reputation:

Please check the following tutorial here. its having 2 scenarios :

  1. Standard Jquery.
  2. Oracle Jet Common model.

In the example that you provided you are using the Oracle jet Common model, which is very good for CRUD operation over Rest webservice.

I advice you also to take alook at the Standard Jquery scenario which is very helpful and easy to use.

Hope that helps.

Upvotes: 1

Koshinae
Koshinae

Reputation: 2320

At the end of your CustomerViewModel you probably miss actually setting the datasource observable:

self.datasource(new oj.CollectionTableDataSource(self.DeptCol()));

Upvotes: 0

Related Questions