我该如何使用AngularJS和serializeJSON CFQUERY [英] how can I use AngularJS and a serializeJSON cfquery

查看:149
本文介绍了我该如何使用AngularJS和serializeJSON CFQUERY的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想看看AngularJS,用CF后端

I am trying to take a look at AngularJS, with a cf backend

我有以下的code,拉了一个名为getIndex定期CFQUERY这列拉五个行,每行(名字,姓氏)

I have the following code that pulls a regular cfquery called getIndex which pulls five rows of columns each (firstName, lastName)

var theQuery = <cfoutput>#serializeJSON(getIndex,true)#</cfoutput>;
        var theData = theQuery.DATA

        function dataLooper($scope){
            $scope.people = theData;
            console.log($scope.people);
        }

控制台日志生成

对象{F​​IRSTNAME = [5],LASTNAME = [5]}

Object { FIRSTNAME=[5], LASTNAME=[5]}

我的HTML看起来像

<div ng-controller="dataLooper">
          <div ng-repeat="person in people">
          {{person}} - {{person.FIRSTNAME}}<br>
          </div>
</div>

产生

    ["Yasteel","Kyleigh","Gary","Nick","Kerry-Leigh"] -
["Si","No","Ho","Ga","Gr"] - 

显然我失去了一些东西,因为这是不是我所期待的。我猜测,这是因为AngularJS正在寻找一个Arrray而不是一个对象。我不知道,但我希望serializeJSON会给我一些类型的可用对象没有很多额外的操纵。有人能指出我朝着正确的方向吗?

Obviously I am missing something as this isn't what I expected at all. I am guessing that it is because AngularJS is looking for an Arrray instead of an object. I am not sure but I was hoping that serializeJSON would give me some type of usable object without a lot of extra manipulation. Can someone point me in the right direction?

推荐答案

@马克感谢您的帮助。我的问题是明确约CFQUERY转换的东西ANGULAR可以处理。从本·纳德尔的一点点帮助,<一个href=\"http://www.bennadel.com/blog/2439-My-Experience-With-AngularJS-The-Super-heroic-JavaScript-MVW-Framework.htm?&_=0.6299782912246883&_=0.9592064458411187#comments_41352\"相对=nofollow>文章有关角和的有关查询转换为结构数组文章。我把它完成。

@Mark Thanks for the help. My question was specifically about converting a CFQUERY to something ANGULAR could deal with. With a little help from Ben Nadel's article about Angular and an article about converting a query to an array of structs. I got it completed.

有关将发现这个去拿本的的 queryToArray 。这里是一个包含列的查询为例名字,姓氏,年龄

For those CFers that will find this go get Ben's queryToArray. Here is an example with a query that contains the columns firstName, lastName, age.

<cfscript>
  a = createObject('component','angular');
  getQuery = a.getQuery();
  QueryArray = a.queryToArray(getQuery);
</cfscript>

<script type="text/javascript"> 
  var theQuery = <cfoutput>#serializeJSON(QueryArray)#</cfoutput>;
  function dataLooper($scope){
    $scope.people = theQuery;
  }
</script>

<div ng-controller="dataLooper">
  <div ng-repeat="person in people">
  {{person.FIRSTNAME}} - {{person.LASTNAME}} - {{person.AGE}}<br>
  </div>
</div>

我希望这可以帮助别人谁是努力学习角!

I hope this helps someone else who is trying to learn Angular!

这篇关于我该如何使用AngularJS和serializeJSON CFQUERY的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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