tags:

views:

145

answers:

2

In CF8, I have a working cftree with an RSS feed per node (multiple nodes). The problem is that I am not currently using a bind which means that all the feeds are read when the page is loaded which takes a very long time. What I want to do is bind the cftreeitem to a cfc so that the feed is only read when the user selects the parent cftreeitem and not on page load. The page is not throwing an error but none of the children nodes of the feed are showing under the parent.

cfm:
<cfform name="RSS_exercise">
<cftree name="Xfeeds" format="html" cache="no">
    <cftreeitem value="elite"  display="<div style='color:##4c4c4c'>ELITE FTS</div>" queryasroot="true" expand="no">
        <cftreeitem value="" bind="cfc:components.rssQ.getEliteRSS({cftreeitempath}, {cftreeitemvalue})">
</cftree>
</cfform>

cfc:
<cffunction name="getEliteRSS" access="remote" returntype="any" hint="gets EliteFTS RSS feed">
<cfargument name="itemPath" type="string" required="false"/>
<cfargument name="itemValue" type="string" required="false"/>
<cffeed source="http://feeds2.feedburner.com/EliteftsArticles" properties="eliteProps" query="eliteRSS">
<cfset var feedArray = ArrayNew(1) />
<cfset var feed = StructNew() />
<cfset var i = 1 />
<cfoutput query="eliteRSS">
    <cfset feed.value = "" />
    <cfset feed.display = "#title# <div style='color:gray'>Published: #DateFormat(publisheddate)#</div><br/>" />
    <cfset feed.href = "#rsslink#" />
    <cfset feed.target = "_blank" />
    <cfset feed.parent = "elite" />
    <cfset feed.queryAsRoot = "false" />
    <cfset feed.expand = "no" />
    <cfset feedArray[i] = Duplicate(feed) />
    <cfset var i = "i++" />
</cfoutput>
<cfreturn feedArray />
</cffunction>

Thank you very much for any help.


Made the following changes and now get the output, but it is nested/looped and I can't get the top level parent node so that they are not all flat. The point of doing this was so that there would be 1 parent that would not load the feed until checked.

cfm
<cfform name="RSS_exercise">
<cftree name="Xfeeds" format="html" cache="no">
    <cftreeitem bind="cfc:components.rssQ.getEliteRSS({cftreeitempath}, {cftreeitemvalue})">
</cftree>
</cfform>

cfc
<cffunction name="getEliteRSS" access="remote" returntype="array" output="no" hint="gets EliteFTS RSS feed">
<cfargument name="itemPath" type="string" required="false"/>
<cfargument name="itemValue" type="string" required="false"/>
<cfset var feedArray = ArrayNew(1) />
<cfset var feed = StructNew() />
<cfset var i = 1 />
<cffeed source="http://feeds2.feedburner.com/EliteftsArticles" properties="eliteProps" query="eliteRSS">
    <cfloop query="eliteRSS">
        <cfset StructClear(feed) />
        <cfset feed.value = "1" />
        <cfset feed.display = "#title# <div style='color:gray'>Published: #DateFormat(publisheddate)#</div><br/>" />
        <cfset feed.href = "#rsslink#" />
        <cfset feed.target = "_blank" />
        <cfset feed.parent = "elite" />
        <cfset feed.queryAsRoot = "false" />
        <cfset feed.expand = "no" />
        <cfset feedArray[i] = Duplicate(feed) />
        <cfset i++ />
    </cfloop>         
    <cfreturn feedArray />
</cffunction>
+1  A: 

First of all you have to check two things:

  1. Make sure you return the JSON-encoded array (see manual).
  2. Install Firebug in your Firefox and track exact requests and responses using Console tab.

In the CFC you should use provided arguments to filter the data from feed. Maybe kind of QoQ on the fetched data.

Also few notes about your server-side code.

You don't have to use # everywhere, but you should use explicit scoping:

<cfset feed.href = "#rsslink#" />
<cfset feed.href = eliteRSS.rsslink />

You don't have to duplicate the structures and track the index. This can be much simpler:

<cfloop query="eliteRSS">
    <cfset feed = {} />
    ...
    <cfset ArrayAppend(feedArray, feed) />
</cfloop>  
Sergii
@Sergii: thanks for the feedback. The code returns the JSON array, the issue now is that it's infinitely nested with no parent. I did get rid of the index and used your idea to clean up the cfc - thanks. On the usage of #, since the query is actually a cffeed and those are the attributes for the tree display, I can't get it to work with explicit scoping.
JS
+1  A: 

My first issue was not using the leafnode=true attribute for all the items within the feed. Then my next biggest issue was not properly setting the arguments.value so what was happening is that it was firing the cfc off every time a node was selected which just repeated the cffeed, again. Here is the cfc code that works as I had hoped:

<cffunction name="getEliteRSS" access="remote" returntype="array" output="no" hint="gets EliteFTS RSS feed">
    <cfargument name="path" required="true"/>
    <cfargument name="value" required="true"/>
    <cfset var feedArray = ArrayNew(1) />
    <cfset var feed = StructNew() />

    <cfif arguments.value IS "">
        <cfset feed.value = "elite" />
        <cfset feed.display = "<div style='color:##4c4c4c'>ELITE FTS</div>" />
        <cfset feed.leafnode = "false" />
        <cfset feed.expand = "no" />
        <cfset ArrayAppend(feedArray, feed) />
    <cfelse>
        <cffeed source="http://feeds2.feedburner.com/EliteftsArticles" properties="eliteProps" query="eliteRSS">
        <cfloop query="eliteRSS">
            <cfset feed = {} />
            <cfset feed.value = "" />
            <cfset feed.leafnode = "true" />
            <cfset feed.display = "#title# <div style='color:gray'>Published: #DateFormat(eliteRSS.publisheddate)#</div><br/>" />
            <cfset feed.href = "#rsslink#" />
            <cfset feed.target = "_blank" />
            <cfset feed.parent = "elite" />
            <cfset feed.queryAsRoot = "false" />
            <cfset ArrayAppend(feedArray, feed) />
        </cfloop>         
    </cfif>
    <cfreturn feedArray />
</cffunction>
JS