简体   繁体   中英

Knockoutjs mapping doesn't work

This is my http://jsfiddle.net/ENMGp/468/ sample code

My Json object

{
   "VehicleModels":[
      {
         "Name":"Model 1",
         "Model":{
            "MakeName":"Ford"
         },
         "Styles":[
            {
               "StockImage":"http://google.com"
            }
         ]
      },
      {
         "Name":"Model 2",
         "Model":{
            "MakeName":"Ford"
         },
         "Styles":[
            {
               "StockImage":"http://bing.com"
            }
         ]
      }
   ]
}

I want to access Styles array, but my viewmodel doesn't allow me to access

Right now your Styles properties is array, you can access it by Styles()[0].StockImage

  1. Here is the working version for object : http://jsfiddle.net/ysN4m/

  2. And here is the working version for array : http://jsfiddle.net/c6Qvq/

And the other changes is, use <span></span> instead of <span />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM