查询到cfscript在Coldfusion中正确吗? [英] query to cfscript properly in coldfusion?

查看:280
本文介绍了查询到cfscript在Coldfusion中正确吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


澄清:这里的问题是,如何停止使用< cfquery> 来检索数据并将其替换为对API的调用?

CLARIFICATION: The question here is, "how do I stop using <cfquery> to retrieve data and replace it with a call to an API?"

我有一个sql查询,需要帮助将其转换为cfscript。但是,如您所见,我已尝试对其进行转换。但是,如果我在正确的路径上从sql查询转换为cfscript,则需要进行一些验证。如果没有,有人可以通过将SQL查询转换为cfscript来帮助我吗?谢谢您的帮助。这是我的代码。

I have a sql query where I need help to convert it to cfscript. However as you can see I have tried converting it. But, I need some verification if I am on the right path to convert from sql query to cfscript. if not, can anyone help me by converting from sql query to cfscript? thanks for the help. here is my code.

CFSCRIPT:

<cfset jsonDatas = fileRead("c:\Users\Desktop\MyApi.json" )>      
<cfset jsonData = deserializeJSON(jsonDatas) />       
<cfif arrayLen(jsonData)>  
  <cfloop array="#jsonData#" index="prop">       
    <cfoutput>  
      <cfscript>  
        // writedump(jsonData);for (item in jsonData[1])   {  
          if (#prop.payGrade# == 0) {
                 #prop.divisionNbr#;        
         #prop.probationBeginDate#;        
         #prop.legacyStatus#;        
         #prop.payStep#;        
         #prop.creationDate#;           
          } 


推荐答案

这确实是一条评论,但是我需要大量空间来编写它。

This is really a comment, but I need a lot of space to write it.

您是否要从远程源获取数据并将其显示在网页上?您要执行类似的操作吗?

Are you looking to get data from a remote source and display it on a web page. Are you looking to do something like this?

我认为我们需要澄清哪些是客户端技术,哪些是服务器端技术。

I think we need to clarify which are client side technologies and which are server side technologies.

更新基于评论**

考虑VueJS解决方案

Consider a VueJS solution

<!-- Showing stuff on screen -->
<div id="app">
  {{ info }}
</div>

我可以在屏幕上显示内容。这类似于 #info#

I can show stuff on the screen. This is similar, but not identical to #info#

<!-- Getting data -->
<cfscript>
new Vue({
  el: '#app',
  data () {
    return {
      info: null
    }
  },
  mounted () {
    axios
      .get('https://api.coindesk.com/v1/bpi/currentprice.json')
      .then(response => (this.info = response))
  }
})
<cfscript>

这是从远程源获取数据并将其放入javascript变量中。

And this is getting data from a remote source and putting that data into a javascript variable.

说明

那我为什么要使用Javascript而不是ColdFusion? Javascript在浏览器上运行; ColdFusion在服务器上运行。如果要在浏览器上使用API​​,则必须使用基于浏览器的技术。

So why am I doing this with Javascript rather than ColdFusion? Javascript runs on the browser; ColdFusion runs on the server. If you want to consume an API on the browser, you have to use browser based technologies.

我的示例在VueJS中,但是Angular和React也可以选择。这有点过时,但是jQuery也可以做这种事情。

My example is in VueJS, but Angular and React are also options. It is a bit dated, but jQuery can do this kind of stuff too.

代码源:> https://vuejs.org/v2/cookbook/using-axios-to-consume-apis.html

这篇关于查询到cfscript在Coldfusion中正确吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆