对象的Javascript关联对象按子对象的值排序

时间:2014-05-19 15:35:46

标签: javascript sorting object associative-array

我有一个javascript对象,如下所示

var siteStat = {
  "anchorpage.htm": {
    "v": "2",
    "u": "2",
    "page": "/anchorpage.htm"
  },
  "captivatetest.htm": {
    "v": "19",
    "u": "6",
    "page": "/draft/captivatetest.htm"
  },
  "homepage.htm": {
    "v": "3",
    "u": "2",
    "page": "/homepage.htm"
  },
  "newpage.htm": {
    "v": "4",
    "u": "4",
    "page": "/newpage.htm"
  },
  "copyfrom.htm": {
    "v": "4",
    "u": "3",
    "page": "/copyfrom.htm"
  }
}

我能够编写一个函数来按键对对象进行排序(anchorpage.htm,captivatetest.htm,copyfrom.htm等等)但是现在我希望整个对象按照孩子的一个值排序对象即按“v”的值排序,因此排序的对象最终看起来像(captivatetest.htm(obj),copyfrom.htm(obj),newpage.htm(obj),homepage.htm(obj),anchorpage.htm (OBJ))

有没有办法做到这一点?提前谢谢

0 个答案:

没有答案