Docpad的查询工具可以调用哪些方法? [英] What methods can be called on Docpad's Query tools?

查看:71
本文介绍了Docpad的查询工具可以调用哪些方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Docpad的文档中,它列出了一系列查询助手.这是链接.下面的列表显示在底部.这些帮助程序中有@ getCollection,@ getFiles,@ getFilesAtPath等.但是,在任何地方都没有迹象表明我能够找到这些帮助程序返回的对象类型以及可以对它们调用哪种方法,如何检索数据等? Docpad文档中有一些示例,例如入门指南显示了如何循环浏览为我们的页面添加菜单列表"部分中的html页面集合.由此可以看出,这里返回的对象具有toJSON()方法,可以对它们进行调用.但是还有什么呢?该文档还说明了这些帮助器函数是某种形式的Query-Engine对象,但在(Query-Engine文档)[

In Docpad's documentation it lists a series of Querying helpers. Here's the link. The following list appears at the bottom. Among these helpers are @getCollection, @getFiles, @getFilesAtPath, etc. But there is no indication anywhere that I have been able to locate about what kind of objects are returned by these helpers, and what sort of methods can be called on them, how does one retrieve data, etc? There are a few examples in the Docpad documentation, for example the beginner's guide shows how you'd loop through a collection of html pages in the section "ADDING A MENU LISTING FOR OUR PAGES". From this one can glean that the objects returned here have a method toJSON() that one can call on them. But what else? The documentation also explains that these helper functions are Query-Engine objects of some sort, but in the (Query-Engine documentation)[http://learn.bevry.me/queryengine/guide] I was unable to find any description of how to manipulate these objects. So my question is: does anyone know what the structure of these objects are and how they can be manipulated? Is there a document that I'm missing somewhere?

推荐答案

我如何使用简单的词语来理解它:

How I understand it using simple man words:

因此,在docpad中,文档默认情况下被解释为yaml文件(内容+元数据).因此,您的查询返回的对象就是您解析为json的这个Yaml文件.

So in docpad documents are by default interpreted as yaml files (content+metadata). So your query returns object that is this yaml file that you parse to json.

重要的是,这个yaml文件不仅是您"定义的元数据+内容,而且还是此处定义的一些其他元数据

Important to know is that this yaml file is not only "your" defined metadata + content but also some additional metadata defined here http://docpad.org/docs/meta-data. So this is a lot of additional data that you can access.

我假设您使用ECO模板,并且您可能知道这全都与CoffeeScript有关.因此toJSON()方法只是您可以使用的javascript方法之一.我没有尝试检查它,但我只是注意到我想用coffeescript解决的任何事情在ECO中都是可行的.因此,一旦您将查询返回的对象解析为json,就可以执行任何操作并在JSON对象上调用所需的任何方法.

I assume you use ECO templating and you probably know that it is all about CoffeeScript. So toJSON() method is just one of javascript methods that you can use. I didn't try to check it but I just noticed that anything I want to solve with coffeescript is doable in ECO. So once you parse the object returned by your query to json, you can do anything and call any method you want on JSON object.

每当我查询文件文档时,都会在"for"循环中添加<%console.log @document%>.它在控制台中返回整个json对象.这样一来,您就可以轻松查看查询返回了哪些对象以及可以从中获取哪些数据.

Whenever I query for docs of files, I add: <% console.log @document %> to my "for" loop. It returns in the console the whole json object. So you can easily see what objects are returned with your query and what data you can take out of them.

希望有帮助.干杯

这篇关于Docpad的查询工具可以调用哪些方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆