如何在Meteor中呈现嵌套集合?(How to render nested collections in Meteor?)
概要:
嵌套在父类别中的子类别不会在流星模板中呈现。细节:
考虑一下'Category'的数据模型:// Model Schema Category { idCategory : 20, (id of the category itself) idCategoryParent : 0, (idCategory of our parent category) defaultLabel : "Movies" (our label) }
有父类别和子类别。 父类别的idCategoryParent属性值为0.子类别将其父类的idCategory作为它们的idCategoryParent属性进行存储。 我试图循环访问这些类别的一个集合,并按以下方式呈现它们:
<b>Movies</b> // parent category is in bold <ul> // child categories are rendered as an unordered list <li>Horror</li> <li>Comedy</li> <li>Action</li> <li>Drama</li> </ul> <b>Music</b> <ul> <li>Rock</li> <li>Classical</li> <li>Ambient</li> </ul>
但是,这是我实际得到的:
<b>Movies</b> <ul> // empty... </ul> <b>Music</b> <ul> </ul>
源代码:
// How we get the 'categories_parents' data Template.content.categories_parents = function (){ /* * Get all parent categories (categories with an idCategoryParent of 0) */ var parents = Categories.find({idCategoryParent:0}); var pCount = parents.count(); for (var i = 0; i < pCount; i++){ var pId = parents.db_objects[i]['idCategory']; /* * Get all child categories of the parent (categories with * an idCategoryParent equal to value of parent category's idCategory). */ var children = Categories.find({idCategoryParent:pId}); var cCount = children.count(); /* * Assign the child categories array as a property of the parent category * so that we can access it easily in the template #each expression */ parents.db_objects[i]['children'] = children; } return parents; } // This is our template <template name="content"> <h1>Categories</h1> {{#each categories_parents}} <b>{{defaultLabel}}</b><br /> <ul> {{#each children}} <li>{{defaultLabel}}</li> {{/each}} </ul> {{/each}} </template>
其他模板配置我曾尝试进行故障排除:
{{#each children}} <li>A Child Exists Here</li> // Even this never rendered... no children? {{/each}}
任何线索,为什么发生这种情况将不胜感激。
Summary:
Child categories nested inside of Parent Categories are not getting rendered in a Meteor template.Details:
Consider a data model for 'Category' as such:// Model Schema Category { idCategory : 20, (id of the category itself) idCategoryParent : 0, (idCategory of our parent category) defaultLabel : "Movies" (our label) }
There are parent categories and child categories. Parent categories have an idCategoryParent property value of 0. Child categories store the idCategory of their parents as their idCategoryParent property. I'm trying to loop through a collection of these Categories and render them in the following way:
<b>Movies</b> // parent category is in bold <ul> // child categories are rendered as an unordered list <li>Horror</li> <li>Comedy</li> <li>Action</li> <li>Drama</li> </ul> <b>Music</b> <ul> <li>Rock</li> <li>Classical</li> <li>Ambient</li> </ul>
However, this is what I actually get:
<b>Movies</b> <ul> // empty... </ul> <b>Music</b> <ul> </ul>
Source Code:
// How we get the 'categories_parents' data Template.content.categories_parents = function (){ /* * Get all parent categories (categories with an idCategoryParent of 0) */ var parents = Categories.find({idCategoryParent:0}); var pCount = parents.count(); for (var i = 0; i < pCount; i++){ var pId = parents.db_objects[i]['idCategory']; /* * Get all child categories of the parent (categories with * an idCategoryParent equal to value of parent category's idCategory). */ var children = Categories.find({idCategoryParent:pId}); var cCount = children.count(); /* * Assign the child categories array as a property of the parent category * so that we can access it easily in the template #each expression */ parents.db_objects[i]['children'] = children; } return parents; } // This is our template <template name="content"> <h1>Categories</h1> {{#each categories_parents}} <b>{{defaultLabel}}</b><br /> <ul> {{#each children}} <li>{{defaultLabel}}</li> {{/each}} </ul> {{/each}} </template>
Other template configurations I have tried in troubleshooting:
{{#each children}} <li>A Child Exists Here</li> // Even this never rendered... no children? {{/each}}
Any clues as to why this is happening would be appreciated.
原文:https://stackoverflow.com/questions/13750854
最满意答案
查询的fetch参数可能很棘手。 如果提供
fetch=true
您将获得查询类型(Story,Defect)上存在的所有字段。 如果该字段也是域对象(如任务或缺陷),您将只获得这样的精简ref对象{ "_ref": "/task/1234.js" }
如果要在子对象上填充字段,则需要指定要在fetch param
fetch=Name,FormattedID,Tasks
显示的字段。 这将返回如下所示的对象:{ "HierarchicalRequirement" : { "Name" : "StoryName", "FormattedID" : "S1234", "Tasks" : [ { "_rallyAPIMajor": "1", "_rallyAPIMinor": "26", "_ref": "https://rally1.rallydev.com/slm/webservice/1.26/task/9872916743.js", "_refObjectName": "Update XYZ when ABC", "_type": "Task", "FormattedID" : "T1", "Name" : "Update XYZ when ABC" }]
}
如果有帮助,请告诉我
The fetch parameter can be tricky with queries. If you provide
fetch=true
you will get all of the fields that exist on the queried type (Story,Defect). If the field is also a domain object (like a tasks or a defect) you will only get the thin ref object like this{ "_ref": "/task/1234.js" }
If you want to get fields populated on the sub-objects you will need to specify the fields you want shown in the fetch param
fetch=Name,FormattedID,Tasks
. This would return an object like the one below:{ "HierarchicalRequirement" : { "Name" : "StoryName", "FormattedID" : "S1234", "Tasks" : [ { "_rallyAPIMajor": "1", "_rallyAPIMinor": "26", "_ref": "https://rally1.rallydev.com/slm/webservice/1.26/task/9872916743.js", "_refObjectName": "Update XYZ when ABC", "_type": "Task", "FormattedID" : "T1", "Name" : "Update XYZ when ABC" }]
}
Let me know if that helped
相关问答
更多-
实际上,集会中的讨论项目是一个集会工件,就像缺陷,故事或任务一样。 为了做你想做的事,你需要创建一个新的讨论工件(或者在拉力API术语中使用ConversationPost),并告诉它哪个现有工件(在你的情况下是一个缺陷)与自己相关联。 rally = Rally(server, user, password) rally.enableLogging('rallyConnection.log') rally.setProject("RallyTestPrj") defectID = 'DE9221' di ...
-
在1.x版本的WSAPI中,可以获取对象的子集合。 HierarchicalRequirement.Defects,TypeDefinition.Attributes和HierarchicalRequirement.Tasks是这些子集合字段的常见示例。 出于性能原因,不再可能在2.x版本的WSAPI中执行此操作。 现在每个对象集合都有自己独特的引用。 这意味着现在可以单独查询,分页,排序和过滤这些集合。 现在,在故事中获取缺陷将返回一个包含计数的对象和从中检索集合数据的uri。 ref uri通常是格式/ ...
-
由于LookbackAPI提供历史数据,您可以在特定时间点查询故事并获得当时完成的点数。 没有Rally生成的速度,因此必须手动访问和汇总。 例如,我的迭代开始于8月7日,并于8月14日结束,但如果我想要8月10日的数据,我使用: https://rally1.rallydev.com/analytics/v2.0/service/rally/workspace/1234/artifact/snapshot/query.js?find={"Iteration":5678,"_TypeHierarchy":" ...
-
如何解析从Ruby工具包返回的Rally Descripton缺陷(how to parse a Descripton of Rally defects returned from Ruby toolkit)[2022-05-20]
安装sanitize gem后 gem install sanitize 此示例代码将删除标记: require 'rally_api' require 'sanitize' #Setup custom app information headers = RallyAPI::CustomHttpHeader.new() headers.name = "My Utility" headers.vendor = "Nick M RallyLab" headers.version = "1.0" # Con ... -
如何根据版本名称或OID查询Rally的Lookback API?(How to query Rally's Lookback API based on Release Name or OID?)[2023-08-12]
哎呀,我最后的简单错误,但我会发布它,以防其他人试图做同样的事情:项目OID必须与你试图查询的版本中的项目相同。 或者更好的是,只需删除项目参数! Oops, simple mistake on my end but I'll post it just in case anyone else is trying to do the same thing: the project OID has to be the same as the project which is in the release you ... -
您可以通过一个查询获得Rally API要求,缺陷和所有任务(Can you GET Rally API requirements, defects, and all tasks with one query)[2021-10-19]
查询的fetch参数可能很棘手。 如果提供fetch=true您将获得查询类型(Story,Defect)上存在的所有字段。 如果该字段也是域对象(如任务或缺陷),您将只获得这样的精简ref对象 { "_ref": "/task/1234.js" } 如果要在子对象上填充字段,则需要指定要在fetch param fetch=Name,FormattedID,Tasks显示的字段。 这将返回如下所示的对象: { "HierarchicalRequire ... -
使用Python中的Rally REST API复制缺陷的首选方法(Preferred method to copy a defect using Rally REST API in Python)[2023-08-08]
看看这个问题的Python答案(有2个答案,另一个是Ruby)。 Rally API:如何复制测试文件夹和成员测试用例 答案包含一个复制测试用例和附件的python脚本。 尽管该脚本适用于测试用例,但逻辑应该很容易适应缺陷,因为操作基本上是相同的 - 只有字段属性会有所不同。 该脚本使用附件,标签等进行复制,几乎是整个工件。 Final solution including Mark W's code for copying attachments def getDataCopy( data ): ... -
将Release添加到您的提取中。 这应包括每个缺陷和链接故事的结果发布。 Add Release to your fetch. That should include the release in the results for each defect and linked story.
-
您可以通过查询TypeDefinition并查看AttributeDefinitions集合来查找该信息。 在每个属性定义上都有一个名为AllowedValues的集合,您可以在其中找到该字段的合法选项。 You can find that information by querying the TypeDefinition's and looking at the collection of AttributeDefinitions. On each Attribute Definition there ...
-
这是一个通过特定版本和故事所有者过滤故事的示例。 它还可以获取每个故事的任务集合,并通过单独的请求进行水合。 static void Main(string[] args) { int storyCount = 0; int taskCount = 0; RallyRestApi restApi; restApi = new RallyRestApi("apiuser@co.com", "secr ...