how can I use AngularJS and a serializeJSON cfquery

后端 未结 2 1432
小蘑菇
小蘑菇 2021-01-21 09:08

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

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

相关标签:
2条回答
  • 2021-01-21 09:32

    ng-repeat can handle an array or an object. For an object, use the "(key, value)" syntax.

    This won't solve your problem though, unless you reformat your data like so:

    { 'Yasteel':'Si', 'Kyleigh':'No', ... }
    

    Then you can do this:

    <div ng-repeat="(first,last) in people">
        {{first}} - {{last}} <br>
    </div>
    
    0 讨论(0)
  • 2021-01-21 09:42

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

    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!

    0 讨论(0)
提交回复
热议问题