将 RSS 读取 cfc 绑定到 cftreeitem
在 CF8 中,我有一个工作 cftree,每个节点(多个节点)都有一个 RSS 提要。问题是我当前没有使用绑定,这意味着在加载页面时会读取所有提要,这需要很长时间。我想要做的是将 cftreeitem 绑定到 cfc,以便仅在用户选择父 cftreeitem 时读取提要,而不是在页面加载时读取。该页面没有抛出错误,但提要的任何子节点都没有显示在父节点下。
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>
非常感谢您的帮助。
进行了以下更改,现在得到了输出,但它是嵌套/循环的,我无法获取顶级父节点,因此它们并不都是平坦的。这样做的目的是为了让 1 个父级在检查之前不会加载 feed。
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>
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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先,您必须检查两件事:
在 CFC 中,您应该使用提供的参数来过滤源中的数据。也许是对获取的数据进行环比分析。
还有一些关于服务器端代码的注释。
您不必在任何地方都使用#,但您应该使用显式范围:
您不必复制结构并跟踪索引。这可以简单得多:
First of all you have to check two things:
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:
You don't have to duplicate the structures and track the index. This can be much simpler:
我的第一个问题是没有对提要中的所有项目使用 leafnode=true 属性。然后我的下一个最大问题是没有正确设置arguments.value,所以发生的事情是每次选择一个节点时都会触发cfc,而节点又会重复cffeed。这是 cfc 代码,它按照我的希望工作:
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: