所以,我正在尝试在多个列上对Taffy数据库进行排序,并获得意外结果。这个例子:
<script src="./taffy/taffy.js"></script>
<script>
var myTaffyDB = TAFFY([
{"foo":"bar","letter":"A","number_01":48,"number_02":6},
{"foo":"bar","letter":"S","number_01":49,"number_02":2},
{"foo":"bar","letter":"Q","number_01":49,"number_02":3},
{"foo":"bar","letter":"W","number_01":49,"number_02":4},
{"foo":"bar","letter":"P","number_01":49,"number_02":5},
{"foo":"bar","letter":"T","number_01":49,"number_02":6},
{"foo":"bar","letter":"W","number_01":49,"number_02":7},
{"foo":"bar","letter":"Q","number_01":49,"number_02":8},
{"foo":"bar","letter":"A","number_01":49,"number_02":9},
{"foo":"bar","letter":"C","number_01":49,"number_02":10},
{"foo":"bar","letter":"B","number_01":50,"number_02":1}
]);
var tempResultsArray = myTaffyDB({"foo":"bar"})
.order("letter","number_01","number_02")
.select( "letter", "number_01", "number_02")
;
console.log( 'tempResultsArray: ' + tempResultsArray );
</script>
产生以下内容:
A,48,6,A,49,9,B,50,1,C,49,10,P,49,5,Q,49,8,Q,49,3,S,49,2,T,49,6,W,49,4,W,49,7
请注意,Q结果按照49,8到49,3的顺序排序,尽管订单调用逐字逐句,然后是number_01,然后是number_02。
我错过了构建此内容的方式,或者Taffy订购结果的方式有限制吗?
答案 0 :(得分:1)
尝试.order("letter, number_01, number_02")
。
源代码说:// * Purpose: Accept filters such as "[col], [col2]" or "[col] desc" and sort on those columns
。
它对我有用。