locked
How to display my data from one JS to another JS RRS feed

  • Question

  • Hi there,

    So I have two javascript files and I'm having trouble getting the information passed from one to the other. 

    Data.js:

    (function () {
        "use strict"
    
        var dataArray = [
            { fname: "Barry", lname: "Charles", fullname: "Charles Barry"},
            { fname: "Tim", lname: "Sanders", fullname: "Tim Sanders"}
        ];
    
        var dataList = new WinJS.Binding.List(dataArray);
    
        //makes the data public to other parts of the app
        var publicMembers =
            {
                itemList: dataList
            };
        WinJS.Namespace.define("DataExample", publicMembers);
    })();

    I figured making the data public would allow me to use the name elsewhere, but I'm getting publicMembers as undefined in this script:

    demo.js

    (function () { "use strict"; WinJS.UI.Pages.define("/pages/demo.html", { ready: function (element, options) {

    //the following line is throwing the publicMembers is undefined error

    console.log("length of array " + publicMembers.itemList.length); } });

    })();

    I'm assuming the best two ways to go about doing this is to either

    1. In my data.js make the array global instead of public. 

    2. In demo.js add some js that pulls the information from data.js

    Problem is I'm not sure which route to take, or how to do either one. 

    Thanks so much!

    Wednesday, April 17, 2013 1:47 PM

Answers

  • I think you should use "DataExample.itemList" instead of "publicMembers.itemList".
    • Marked as answer by ZachAtttack Wednesday, April 17, 2013 3:05 PM
    Wednesday, April 17, 2013 2:38 PM

All replies

  • I think you should use "DataExample.itemList" instead of "publicMembers.itemList".
    • Marked as answer by ZachAtttack Wednesday, April 17, 2013 3:05 PM
    Wednesday, April 17, 2013 2:38 PM
  • Thaank you. 
    Wednesday, April 17, 2013 3:05 PM