0

我使用 json_builder 从timeline.verite.co 生成时间线所需的JSON 文件,因为它需要采用特定格式。但是,当我加载页面时,它会卡在白色背景和加载 gif 中。如果我给它一个指向一些示例数据的链接,而不是为用户生成的数据,它就可以工作。html 页面 (users/1/events) 工作正常。有人知道为什么吗?我现在已经没有想法了!!

更新:

我让 JS 链接到带有来自 users/1/events.json 的 JSON 粘贴内容的静态文件,它工作正常。所以我假设问题是当 JS 尝试获取它时页面是空白的,并且只有在您实际访问该 URL 时才会填充。我该如何解决这个问题?

生成的 JSON 文件(通过转到 /users/1/events.json 获得):

{
  "timeline": {
    "headline": "Emily",
    "type": "default",
    "text": "A Timeline",
    "startDate": "1922,10,30",
    "date": [
      {
        "startDate": "2012,11,17",
        "endDate": "2012,11,17",
        "headline": "My Birthday",
        "text": "This is my birthday",
        "asset": {
          "media": "http://www.youtube.com/watch?v=dePMU8R131s",
          "credit": "",
          "caption": "Happy Birthday"
        }
      }
    ]
  }
}

必需的语法:

{
    "timeline":
    {
        "headline":"Stuff People Say",
        "type":"default",
        "text":"People say stuff",
        "startDate":"2012,1,26",
        "date": [
            {
                "startDate":"2012,1,26",
                "endDate":"2012,1,27",
                "headline":"Stuff Politicians Say",
                "text":"<p>In true political fashion, his character rattles off common jargon heard from people running for office.</p>",
                "asset":
                {
                    "media":"http://youtu.be/u4XpeU9erbg",
                    "credit":"",
                    "caption":""
                }
            },
            {
                "startDate":"2012,1,10",
                "headline":"Stuff Nobody Says",
                "text":"<p>Have you ever heard someone say “can I burn a copy of your Nickelback CD?” or “my Bazooka gum still has flavor!” Nobody says that.</p>",
                "asset":
                {
                    "media":"http://youtu.be/f-x8t0JOnVw",
                    "credit":"",
                    "caption":""
                }
            }
        ]
    }
}

控制器(相关位):

class EventsController < ApplicationController

  respond_to :json, :html

def myevents
    @events = current_user.events
    respond_with @users
  end

end

路线:

resources :events do
    member do
      get 'myevents'
    end
  end

match 'users/:id/events' => 'events#myevents'

JS调用时间线:

<%= javascript_include_tag "/js/storyjs-embed.js" %>
        <script>
            $(document).ready(function() {
                createStoryJS({
                    type:       'timeline',
                    width:      '800',
                    height:     '600',
                    source:     '/users/<%= current_user.id %>/events.json',
                    embed_id:   'my-timeline'
                });
            });
        </script>
4

1 回答 1

1

我最终找到了答案,表单的 js 没有正确读取 JSON 文件。我需要添加一个回调。

于 2012-10-16T09:49:46.387 回答