如何将图像写入数组

时间:2016-08-26 22:12:55

标签: javascript css

var products =[
  {  "image.src =": "images/shopcart/jello.jpeg", "name": "Lusicious Jello Mix", "description": ["Very Elegant", "Trending item", "Come in Purple"], "price": 80.65 },
  { "image": "images/shopcart/desk.jpeg", "name": "Tarnished Standing Desk", "description": ["Modular", "Works for both Tall and Loud People", "Smells like Productivity"], "price": 1654.99},
  { "image": "images/shopcart/grenade.jpeg", "name": "Hand-made Hand Grenades", "description": ["Such gift!", "Much boom!", "Very safe for kids"], "price": 10.44},
  { "image": "images/shopcart/cookie.jpeg", "name": "Pan-fried Cookie Dough", "description": ["Chocolate", "Family-size", "Hot Mess"], "price": 16.99 },
  { "image": "image/shopcart/hanger.jpeg", "name": "Fancy Dress Hanger", "description": ["Keep organized", "On Sale"], "price": 67.32 },
  { "image": "image/shopcart/mustache.jpeg", "name": "Snarky Britsh Mustache 3-Pack", "description": ["Sharing is caring!", "Hugs not drugs", "As seen on 'So You Think You Can Dance - Nigeria!'"], "price": 1.99 },
];

在数组中查找这些图像的正确语法。我知道src必须在某个地方,不知道在哪里或如何。感谢。

1 个答案:

答案 0 :(得分:0)

您在javascript中编写文字对象,这是一种动态语言。 您没有义务使用特定格式,只需使用适合您的格式。

我建议使用以下

var products = [
{ "name" : "Milk",
  "image": {
 "src": "path/to/my/milkpic",
 "alt": "Milk photo"
}}
]