将 RSS 读取 cfc 绑定到 cftreeitem

发布于 2024-08-16 04:48:55 字数 3121 浏览 2 评论 0原文

在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

笑梦风尘 2024-08-23 04:48:55

首先,您必须检查两件事:

  1. 确保返回 JSON 编码的数组(请参阅 手册)。
  2. 在 Firefox 中安装 Firebug 并使用“控制台”选项卡跟踪准确的请求和响应。

在 CFC 中,您应该使用提供的参数来过滤源中的数据。也许是对获取的数据进行环比分析。

还有一些关于服务器端代码的注释。

您不必在任何地方都使用#,但您应该使用显式范围:

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

您不必复制结构并跟踪索引。这可以简单得多:

<cfloop query="eliteRSS">
    <cfset feed = {} />
    ...
    <cfset ArrayAppend(feedArray, feed) />
</cfloop>  

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>  
枯寂 2024-08-23 04:48:55

我的第一个问题是没有对提要中的所有项目使用 leafnode=true 属性。然后我的下一个最大问题是没有正确设置arguments.value,所以发生的事情是每次选择一个节点时都会触发cfc,而节点又会重复cffeed。这是 cfc 代码,它按照我的希望工作:

<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>

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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文