如何使用 AngularJS 和 serializeJSON cfquery [英] how can I use AngularJS and a serializeJSON cfquery
问题描述
我正在尝试看一下带有 cf 后端的 AngularJS
I am trying to take a look at AngularJS, with a cf backend
我有以下代码可以提取一个名为 getIndex 的常规 cfquery,它每列提取五行(firstName,lastName)
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);
}
控制台日志产生
对象 { FIRSTNAME=[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 正在寻找一个数组而不是一个对象.我不确定,但我希望 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?
推荐答案
@Mark 感谢您的帮助.我的问题是关于将 CFQUERY 转换为 ANGULAR 可以处理的东西.在 Ben Nadel 的 关于 Angular 的文章 和 关于将查询转换为结构数组的文章.我已经完成了.
@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.
对于那些会发现这个的 CFers 去获取 Ben 的 queryToArray.下面是一个包含 firstName、lastName、age 列的查询示例.
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>
我希望这对正在尝试学习 Angular 的其他人有所帮助!
I hope this helps someone else who is trying to learn Angular!
这篇关于如何使用 AngularJS 和 serializeJSON cfquery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!