Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
787 views
in Technique[技术] by (71.8m points)

data structures - Stop ColdFusion from sorting my structs/arrays

I have data represented in CF as an array of structs e.g.:

var foo = [{key = 'bar', value = 'baz', ... }...];

This structure gets iterated over sequentially and then translated to another related struct which looks like:

foo2[key] = {key = 'bar', value = 'baz', ...};

This is then sent to the SerializeJSON() method and sent to the browser. The problem is that the order of the keys in either foo or foo2 are alphabetical instead of in the order they were added. This is causing a problem on the client side as this collection is iterated over again and is expected to be ordered. Any suggestions?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

If your collection is expected to be ordered you need to use an array.

Structs don't guarantee any ordering, and shouldn't be used as such.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...