Skip to Main Content

DevOps, CI/CD and Automation

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

MOOC: Lesson 2 Part 4 - Not sure how to use ojet data source

Prakash Thomas-OracleAug 30 2016 — edited Aug 31 2016

I am not clear how to get the ojet data source with common collections to work based on the example in the training video.

I tried the following:

moviefactory.js:

-------------------

define(['ojs/ojcore'],

  function(oj) {

        var MovieFactory = {

            resourceURL: 'http://movieapp-sitepointdemos.rhcloud.com/api/movies',

           

            //Create Single Movie Instance

            createMovieModel: function(){

                var Movie = oj.Model.extend({

                    urlRoot: this.resourceURL,

                    idAttribute: "_id"

                });

                return new Movie();

            },

            createMovieCollection: function(){

                var Movies = oj.Collection.extend({

                    url: this.resourceURL,

                    model: this.createMovieModel()

                });

                return new Movies();

            }

        };

       

        return MovieFactory;

         

});

library.js:

----------

define(['ojs/ojcore', 'knockout', 'MovieFactory', 'ojs/ojmodel', 'ojs/ojtable', 'ojs/ojcollectiontabledatasource'],

        /**

         * The view model for the main content view template

         */

                function (oj, ko) {

                    function viewModel() {

                        var self = this;

                        var viewModel = {

                            movieCollection: self.MovieFactory.createMovieCollection(),

                            dataSource: ko.observable(),

                            initialize: function () {

                                this.dataSource(new ojCollectionTableDataSource(this.movieCollection));

                                this.movieCollection.fetch();

                            }

                        };

                    }

                    return viewModel;

                });

library.html:

-----------

<h1>Library Content</h1>

<table data-bind="ojComponent: {component: 'ojTable',

            data: dataSource,

            columns: [

                   {headerText: 'Director', field: 'director' },

                   {headerText: 'Title', field: 'tile' },

                   {headerText: 'Genre', field: 'genre' },

                   {headerText: 'Year', field: 'year' },

                  

            ]

             }">

   

</table>

This post has been answered by John JB Brock-Oracle on Aug 31 2016
Jump to Answer
Comments
Post Details
Added on Aug 30 2016
11 comments
818 views