0

如何添加到 data.data.trek.places 对象。例如,如果用户触发了我想添加到该对象的事件,然后能够再次对其进行迭代,但我不知道该怎么做。我找不到类似于带有数组的 push 函数的东西。我的应用程序位于主干之上,也许有一个下划线功能?

我基本上想做:

data.data.trek.places.push({
                            "url" : "/attraction/mauna-kea-summit/19",
                            "img_src" : "http://trekeffect.images.user_images.s3.amazonaws.com/4_36.jpg",
                            "title" : "Mauna Kea Summit",
                            "time_going" : "1368787333",
                            "time_going_hour" : 1,
                            "time_going_minutes" : 55,
                            "duration" : "3600",
                            "id" : 19,
                            "type" : "attraction",
                            "city_id" : 6
                           });

我来自原始ajax的json如下:

{
  "data":{
  "trek":{
     "places" : [
        {
           "url" : "/attraction/mauna-kea-summit/19",
           "img_src" : "http://trekeffect.images.user_images.s3.amazonaws.com/4_36.jpg",
           "title" : "Mauna Kea Summit",
           "time_going" : "1368687333",
           "time_going_hour" : 1,
           "time_going_minutes" : 55,
           "duration" : "3600",
           "id" : 19,
           "type" : "attraction",
           "city_id" : 6
        },
        {
           "url" : "/attraction/mauna-kea-resort-golf-course/20",
           "img_src" : "http://trekeffect.images.user_images.s3.amazonaws.com/4_41.jpg",
           "title" : "Mauna Kea Resort Golf Course",
           "time_going" : "1368704533",
           "time_going_hour" : 6,
           "time_going_minutes" : 42,
           "duration" : "5400",
           "id" : 20,
           "type" : "attraction",
           "city_id" : 6
        }
     ]
  }

} }

4

1 回答 1

3

data.data.trek.places 一个数组。
它与任何其他数组完全一样,只是它恰好被对象的属性引用。

您可以像使用任何其他数组一样使用它。

于 2013-05-19T19:46:57.803 回答