Question

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: "",
       ...
      }
Was it helpful?

Solution

Assign images to viewModel like this:

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

Then access them like this viewModel.images

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top