php知识积累PHP实战PHP经验分享

jq将ajax从后台返回的数据自动排序

2017-04-25  本文已影响59人  hey_沙子

从数据库查询出来的按EXCHANGE_INTEGRAL字段升序(异步分页排序)

[394483] => Array
    (
        [EXCHANGE_INTEGRAL] => 10
        [salePrice] => 39.50
        [skuId] => 394483
        [title] => 吉来 椴树蜂蜜500克/瓶
    )

[389614] => Array
    (
        [EXCHANGE_INTEGRAL] => 12
        [salePrice] => 9.80
        [skuId] => 389614
        [title] => 悠果乐 果汁软糖 香橙味 105g/盒
    )

[403430] => Array
    (
        [EXCHANGE_INTEGRAL] => 16
        [salePrice] => 300.00
        [skuId] => 403430
        [title] => 万家乐电饭煲
    )

结果ajax请求过来的数据顺序却按skuId排序了389614,394483,403430

解决办法:

重组数据结构,不拿skuId作为key,让其默认排序,这样就不会影响排序了

[0] => Array
    (
        [EXCHANGE_INTEGRAL] => 10
        [salePrice] => 39.50
        [skuId] => 394483
        [title] => 吉来 椴树蜂蜜500克/瓶
    )

[1] => Array
    (
        [EXCHANGE_INTEGRAL] => 12
        [salePrice] => 9.80
        [skuId] => 389614
        [title] => 悠果乐 果汁软糖 香橙味 105g/盒
    )

[2] => Array
    (
        [EXCHANGE_INTEGRAL] => 16
        [salePrice] => 300.00
        [skuId] => 403430
        [title] => 万家乐电饭煲
    )
上一篇下一篇

猜你喜欢

热点阅读