Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function () {
- "use strict";
- WinJS.Utilities.startLog({ type: "error", tags: "winjs controls" });
- WinJS.UI.Pages.define("/pages/home/home.html", {
- // This function is called whenever a user navigates to this page. It
- // populates the page elements with the app's data.
- ready: function (element, options) {
- // TODO: Initialize the page here.
- $("#data").append("<font color='red'>TEST</font>");
- $("#adddata").click(addSampleData);
- }
- });
- if ("indexedDB" in window) {
- WinJS.log && WinJS.log("indexedDB available");
- } else {
- WinJS.log && WinJS.log("No indexedDb");
- }
- var myData = new Object();
- myData.db = null;
- myData.open = function () {
- var request = window.indexedDB.open("dataFromWeb", 1);
- request.onupgradeneeded = function (e) {
- WinJS.log("Upgrading...");
- if (!myData.db) {
- myData.db = e.target.result;
- }
- myData.db.createObjectStore("people");
- }
- request.onsuccess = function (e) {
- WinJS.log("Success!");
- myData.db = e.target.result;
- }
- request.onerror = function (e) {
- WinJS.log("Error");
- }
- }
- myData.open();
- function addSampleData() {
- //Assume db is a database variable opened earlier
- var transaction = myData.db.transaction(["people"], "readwrite");
- var store = transaction.objectStore("people");
- //Define a person
- var person = {
- name: "Piotrek",
- email: "piotrek@piotrek.pl",
- created: new Date()
- }
- //Perform the add
- var request = store.add(person, 1);
- request.onerror = function (e) {
- WinJS.log("Error", e.target.error.name);
- //some type of error handler
- }
- request.onsuccess = function (e) {
- WinJS.log("Did it");
- }
- }
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement