basic jaydata initialization

109 Views Asked by At

i have a basic problem with jaydata. My Code:

jQuery( document ).ready(function() {

  $data.Entity.extend("Todo", {

     Id: { type: "int", key: true, computed: true },
     Task: { type: String, required: true, maxLength: 200 },
     DueDate: { type: Date },
     Completed: { type: Boolean }
  });

  $data.EntityContext.extend("TodoDatabase", {

     Todos: { type: $data.EntitySet, elementType: Todo }
  });

  var todoDB = new TodoDatabase({
     provider: 'indexedDb', databaseName: 'MyTodoDatabase'
  });

  todoDB.onReady(function() {
     //Work with todoDB now
  });

});

Of couse i get an Error because the variable Todo in Line:

Todos: { type: $data.EntitySet, elementType: Todo }

is undefined. When I replace Todo with a string for example then TodoDatabase in line:

  var todoDB = new TodoDatabase ({
     provider: 'indexedDb', databaseName: 'MyTodoDatabase'
  });

in not defined / no constructor. So i do not understand the differenz of "Todo" and Todo nor differenz between "TodoDatabase" and TodoDatabase. Please help i have no idea how to use this system correct.

Thank you

1

There are 1 best solutions below

1
Robesz On

JayData 1.4.x+ versions are optimized to use less global objects. There are two options to make the example work with these new JayData versions:

Option 1: Define your entity using a variable:

var Todo = $data.Entity.extend("Todo", {
 Id: { type: "int", key: true, computed: true },
 Task: { type: String, required: true, maxLength: 200 },
 DueDate: { type: Date },
 Completed: { type: Boolean }
});

Option 2: use compatibility script You can use this script to use entity definitions through global variables