Two Collections in one Each loop - meteor

Collection "notes" (markdown): meteor **amazing** and reactjs *learning next*
Collection "links": google - www.google.com and stackoverflow - www.stackoverflow.com
I want to display the notes and links in ONE LIST sorted by the creation date:
1. google - www.google.com
2. meteor - amazing
3. reactjs - learning next
4. stackoverflow - www.stackoverflow.com
and NOT like that:
1. meteor - amazing
2. reactjs - learning next
1. google - www.google.com
2. stackoverflow - www.stackoverflow.com
The "notes" and "links" collections have a completely different structure:
notes = new Mongo.Collection('notes');
{{#each note}}
{filename}}
{{#markdown}} {{note}} {{/markdown}}
{{/each}}
links = new Mongo.Collection('links');
{{#each link}}
{filename}}
<a href={{link}}> {{link}} </a>
{{/each}}
QUESTION:
Should I have one collection for both of them? Is there a Package for this? Or how can I solve this?
If one Item is changed, only this Item should be rendered again.

.fetch() the documents and keys you want from each collection.
.map() the keys from each array into a set of common keys
You'll now have two arrays with common keys
Append one array to the other
Sort the whole array by the key you want to sort by
Return that array from your helper
Display in a single template
Alternatively you can omit step 2 and keep each document in its original structure but then your template is going to have to recognize what kind of document its rendering and display it accordingly.

Related

How to query for existence of child array in Firebase?

Hello Internet Denizens,
I'm using Firebase at the moment and am trying to query the following structure:
items
1
- name: "Car"
- Children
- 2
- 3
2
- name: "Wheels"
3
- name: "Engine"
You can see from this example that I have an array of items with Ids of 1,2, & 3. 1 also has its own sub-array called Children, which is composed of Ids 2 & 3.
How would I make a firebase query that pulled back only the Ids which had an array called children?
At first, I thought something like the following would work:
<my firebase path>.child('items').orderByChild('Children').once('value', function(snap){
// ... No results :(
});
No luck. Next, I tried adding an attribute called hasChildren = true to the Id of 1 and then queried like so.
<my firebase path>.child('items').orderByChild('hasChildren').equalTo(true).once('value', function(snap){
// ... iterate over results, which in this case is the Id 1
});
However, when I do a snap.ForEach(function(data)... and then look at data.val().Children, it's just a blank result, which confuses me because I thought Firebase pulled back all child nodes. Hence, the need to flatten your data.
How do I get those Children values?
** Update ** Plunker Added
http://plnkr.co/edit/9U0ujEwdKi7sgQGmd6IE?p=preview
Looks like this was a comedy of errors.
1) In the simple example, 1, 2, & 3 are ordered, so firebase treats it as an array. In the real world, those numbers are much more random so firebase treats them as an object since they aren't ordered.
2) For some reason, Intellij wasn't showing the Children object's contents. I had to type in something like data.val().Children['3'] to get a value or something like for(var property in data.val().Children) to iterate through the fields. Weird.
3) I STILL can't do .child('items').orderByChild('Children') ... since that returns all records. Oddly enough, however, it returns the ones that have Children first.
DataSnapshot.forEach returns another snapshot in the callback. So instead of trying to access data['Children'], you would have to use data.val().Children.
Looks like modifying my data structure is the best way to go since checking for the existence of an array object isn't possible at this point.

is there a way to do a meteor find() based upon more than one field?

Is there a way to do a meteor find (yes, it will be part of a publish function later, i'm just trying to test this)
that is filtered by more than one field at a time?
for example, let's say I only want to return those users who work at Disney in the IT department.
so far I have
Template.managerReports.disney = function () {
return employees.find({'company':"disney"});
};
//for template helper binding to
<template name="managerReports">
{{#each disney}}
<p>{{name}}</p>
{{/each}}
</template>
and attempts to add multiple comma-separated {field:value} pairs results very nicely in these ALSO being found and added to the disney results. I want to reduce results per added field. only data that matches multiple fields gets found.
am I being totally dumb? what is the usual meteor way to deal with multiple conditional finds?
If you want to find users who work for disney AND in the IT department:
employees.find($and: [{company: 'disney'}, {department: 'it'}]);
However, mongodb provides an implicit AND operation when specifying a comma separated list of expressions. So this is more commonly written as:
employees.find({company: 'disney', department: 'it'});
If you want to find users who work for disney OR in the IT department:
employees.find($or: [{company: 'disney'}, {department: 'it'}]);
You need to pass a javascript object, not comma-separated values:
Employees.find({
company: 'disney',
department: 'marketing',
salary: {$gt: 100000},
});

Content delivery criteria for getting data from LinkInfo Table

I need to fetch component ids from link info table based where url field matches a certain value. Is there any criteria to get data from link_info table in tridion using content delivery api.
for example
Regards,
Rajendra
Components don't have URLs, so that might be a bit tricky to achieve.
Pages do have URLs, and you can use the PageFactory class to find them, something along these lines:
PageMetaFactory factory = new PageMetaFactory(publicationId);
PageMeta meta = factory.getMetaByUrl(publicationId, "/my/url");
List<ComponentPresentationMeta> cpMetas = meta.getComponentPresentationMetas();
This will contain a list of all component presentations for a given page. You can use cpMeta.getComponentId() to get the component ID of the component presentation in question.
You may want to start asking Tridion questions here: http://tridion.stackexchange.com

how to change a drupal views output

I need to create a block with eg the latest comments on the site.
when using views, concegui select the data I wanted, but the problem is that I need to edit the output of view (specify the html). I tried to make a tpl, but the fields when they get to this, are already formatted ([#markup]). also tried to make a block programmatically by accessing the fields of view, via $comments = views_get_view('last_opinions');, but so the fields do not bring content, but for example, ids (for referrals), or integers (in the case of dates), ....
basically, how to change views output?
views->your view->advance(third panel)-> Theme: Information -> click Information ->choose tpl as per your requirement and find $row which actually prints your output

Adobe Livecycle -- Is there a way to use the same binding more than once?

Version: 8.2.1.5161.566259
It seems that attempting to bind the same item from my Data View to more than one field...
For example, I have a collection of objects named "Customers". I have one part of my PDF list customer names and another list their addresses. However, the addresses never show up because the Customers array is already bound somewhere else.
A hierarchy view:
- Page
- Customer Names (subform) - $record.Customers.Customer[*]
Customer.Name - $.FullName
+ Other Section (subform)
- Customer Addresses (subform) - $record.Customers.Customer[*]
Address 1 - $.Address1
Address 2 - $.Address2
City - $.City
State - $.State
ZipCode - $.ZipCode
The problem is that the Customer Addresses subform doesn't actually get bound. Any way to fix this that is simple. I know in WPF and Silverlight you can bind to the same data property multiple times, so I figured it was similar with Adobe LiveCycle.
Nope, unfortunately multiple data-binding doesn't work on repeated element nodes ...
The only workaround I know is to fill one of the two section programatically using JavaScript.

Resources