locked
regarding HTML5/Javascript

    Question

  • hi,

    I am working on metro ui from past 1 month.i have 2 questions to ask

    1)how to add data dynamically in JavaScript. I have found code for c# but I need it for JavaScript.

    2)how to add bookmarks to a news application.

    Tuesday, August 7, 2012 10:14 AM

Answers

  • Hi

    For your first question:

    You can use WinJS.Binding.List object  to store your data.

    Then use WinJS.Binding.as to bind the Data to a Winjs.Namespace.

    For example:

    //define the data namespace.
    (function () {
    "use strict";
    var shoppingItemsList = new WinJS.Binding.List();
    var preferredStoresList = new WinJS.Binding.List();
    WinJS.Namespace.define("ViewModel", {
    UserData: WinJS.Binding.as({
    homeZipCode: null,
    getStores: function () {
    return preferredStoresList;
    },
    addItem: function (newName, newQuantity, newStore) {
    shoppingItemsList.push({
    item: newName,
    quantity: newQuantity,
    store: newStore
    });
    }
    })
    });
    // statements to add test data removed for brevity
    })();
    //add data to the namespace
    ViewModel.UserData.addItem("Ice Cream", 1, "Vanilla", "Walmart");

    The WinJS.Binding.as method replaces data properties with getters and setters that trigger
    notifications when the property value change.

    For the second:

    Can you explain it clearer?

    Tuesday, August 7, 2012 4:52 PM
  • No you would have to design and implement what you think bookmarks should look like and how they would behave in your application.  There is no generic concept of bookmarks.

    -Jeff


    Jeff Sanders (MSFT)

    Thursday, August 9, 2012 5:26 PM
    Moderator

All replies

  • Hi

    For your first question:

    You can use WinJS.Binding.List object  to store your data.

    Then use WinJS.Binding.as to bind the Data to a Winjs.Namespace.

    For example:

    //define the data namespace.
    (function () {
    "use strict";
    var shoppingItemsList = new WinJS.Binding.List();
    var preferredStoresList = new WinJS.Binding.List();
    WinJS.Namespace.define("ViewModel", {
    UserData: WinJS.Binding.as({
    homeZipCode: null,
    getStores: function () {
    return preferredStoresList;
    },
    addItem: function (newName, newQuantity, newStore) {
    shoppingItemsList.push({
    item: newName,
    quantity: newQuantity,
    store: newStore
    });
    }
    })
    });
    // statements to add test data removed for brevity
    })();
    //add data to the namespace
    ViewModel.UserData.addItem("Ice Cream", 1, "Vanilla", "Walmart");

    The WinJS.Binding.as method replaces data properties with getters and setters that trigger
    notifications when the property value change.

    For the second:

    Can you explain it clearer?

    Tuesday, August 7, 2012 4:52 PM
  • thanks for your answer. and the second one is regarding adding bookmarks  that means if we have to save a link we have favorites bar in the same way we have bookmarks bar also.

    http://msdn.microsoft.com/en-us/library/windows/apps/hh868272.aspx

    in the above link I have found an example regarding news app in that it has adding bookmarks concept but I didn't find any code to add bookmarks.

    and I have one more question

    can we store data using database? In some sites I have read that it is not possible but in some it is written that by using SQLite it is possible. can u give me the exact answer?

    Wednesday, August 8, 2012 9:26 AM
  • There is no built in support for bookmarks.  You must design and implement this.  You can use SQLight, a web based data storage or indexeddb in your application.

    Jeff Sanders (MSFT)

    Wednesday, August 8, 2012 12:36 PM
    Moderator
  • thanks for your answer. could u please say how to implement bookmarks?
    Thursday, August 9, 2012 7:53 AM
  • No you would have to design and implement what you think bookmarks should look like and how they would behave in your application.  There is no generic concept of bookmarks.

    -Jeff


    Jeff Sanders (MSFT)

    Thursday, August 9, 2012 5:26 PM
    Moderator
  • ok thanks for your valuable answers.
    Friday, August 10, 2012 9:25 AM