Search code examples
javascriptvisual-studio-2012winjs

Add a List of objects into a ViewModel


I am trying to add this list into my view model in order to make some bindings a little bit simpler. However, I can't figure out the syntax in order to do so.

        var images = [
          { name: "Image 1", photo: "/images/image1.jpg" },
          { name: "Image 2", photo: "/images/image2.jpg" },
          { name: "Image 3", photo: "/images/image3.jpg" },
        ];

      var viewModel = {
          favorite: "",
       ...
      }

Solution

  • Assign images to viewModel like this:

      var viewModel = {
          favorite: "",
          images: images
      };
    

    Then access them like this viewModel.images