动画JSON数据?

时间:2013-02-11 16:39:36

标签: json api animation mustache

愚蠢的提问时间。我试图使用Mustache模板系统将我的JSON数据与flipbook插件集成。不用说,这根本不起作用。

我是一个jQuery noobie,所以有没有简单的方法来绑定和动画JSON数据到/与插件(有或没有Mustache标签)?

1 个答案:

答案 0 :(得分:0)

从你的问题来看,推断你想要的东西有点难,但我觉得你已经把所有的东西都放在了一起。首先是您在评论中链接到的示例:https://github.com/blasten/turn.js/wiki/Making-pages-dynamically-with-Ajax

这通过Ajax获取尚未加载的页面,示例代码假定Ajax调用从服务器返回HTML,这可以从那里的代码片段中看到(在添加缺少的'}'之后:

$.ajax({url: "app?method=get-page-content&page="+page})
  .done(function(data) {
     element.html(data);
});

此处done函数通过将data直接注入element来处理从服务器返回的{ "title" : "the title of page N", "text" : "here is some text for the page N." } ,该done应包含当前页面。

我接下来假设你有一个服务器端方法,但该方法返回JSON。让我假设它返回以下结构:

$.ajax({url: "app?method=get-page-content&page="+page})
  .done(function(data) {
     var pageHtml = Mustache.render("<h2>{{title}}</h2><p>{{text}}</p>", data);
     element.html(pageHtml);
});

接下来就是在将结果插入页面之前,将此JSON呈现为data功能中的html。查看README.md上的简短教程,可能如下所示:

<h2>the title of page N</h2><p>here is some text for the page N.</p>

如果服务器返回正确的{{1}},您现在应该看到

{{1}}

出现在页面上。