2

I am using JaydData with Backbone JS. On the start page of application I am using the JayData context as:

$data.Entity.extend('$todo.Types.ToDoEntry', {
    Id: { type: 'int', key: true, computed: true },
    Value: { type: 'string' },
    CreatedAt: { type: 'datetime' },
    ModifiedAt: { type: 'datetime' },
    Done: { type: 'bool' }
});

$data.EntityContext.extend('$todo.Types.ToDoContext', {
    TodoEntries: { type: $data.EntitySet, elementType: $todo.Types.ToDoEntry }
});

$todo.context = new $todo.Types.ToDoContext({ name: provider, databaseName: 'todo' });
$todo.context.onReady({
    success: updateView,
    error: function () {
    $todo.context = null;
    updateView();
}

On this page $todo.context is available for executing database operations. But when I navigate to some other page of application, $todo.context is not available. How can I get the $todo.context on all pages of the Backbone application?

Thanks.

Arvind Bhardwaj
  • 5,231
  • 5
  • 35
  • 49
  • are you actually navigating away from your start page to your new page? or is it handled internally as a single page app – Quince Jun 19 '14 at 11:57
  • @Quince I am using Backbone routes for naviation. So basically it ia a single page app. But problem is when I open the app second time, how do I get the context at that moment. – Arvind Bhardwaj Jun 20 '14 at 06:05

2 Answers2

2

You should be able to reuse the code you provided on other pages. If you wanted to save it accross multiple pages you could look into attaching it to a session variable. Good luck in your endeavors!

Greg
  • 1,845
  • 2
  • 16
  • 26
2

Try to write a new JS file with the '$.todo.context' and load it as a module using require js, This way you can define in every page, this dependency.

Take a look in how to use RequireJS.

http://requirejs.org/docs/start.html

I have a post with this topic in my blog, unfortunately it's only available in portuguese. try to use google to translate.

http://www.rcarvalhojs.com/backbone/2014/06/03/comecando-require-backbone.html

Hope it helps!

rcarvalho
  • 790
  • 1
  • 4
  • 14