1

所以,我试图在多列上对 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 订购结果的方式是否有一些限制?

4

1 回答 1

1

试试.order("letter, number_01, number_02")
源代码说:// * Purpose: Accept filters such as "[col], [col2]" or "[col] desc" and sort on those columns.
它对我有用。

于 2014-11-25T14:17:19.100 回答