2011-12-19 69 views
0

我有以下JSON结构的jqGrid - 分页

JSON

{ 
    "page":"1", 
    "total":"3", 
    "records":"15", 
    "mypage":{ 
     "outerwrapper":{ 
     "innerwrapper":{ 
      "rows":[ 
       { 
        "id":"1", 
        "read": true, 
        "cells": [ 
        { 
         "label":"linkimg", 
         "links": [ 
          { 
           "name":"link1" 
          }, 
          { 
           "name":"link2" 
          }, 
          { 
           "name":"link3" 
          } 
         ] 
        } 
        ] 
       }, 
       { 
        "id":"2", 
        "read": false, 
        "cells": [ 
        { 
         "label":"linkimg", 
         "links": [ 
          { 
           "name":"link1" 
          }, 
          { 
           "name":"link2" 
          } 
         ] 
        } 
        ] 
       }, 
       { 
        "id":"3", 
        "read": false, 
        "cells": [ 
        { 
         "label":"linkimg", 
         "links": [ 
          { 
           "name":"link1" 
          }, 
          { 
           "name":"link2" 
          } 
         ] 
        } 
        ] 
       }, 
       { 
        "id":"4", 
        "read": false, 
        "cells": [ 
        { 
         "label":"linkimg", 
         "links": [ 
          { 
           "name":"link1" 
          }, 
          { 
           "name":"link2" 
          } 
         ] 
        } 
        ] 
       }, 
       { 
        "id":"5", 
        "read": false, 
        "cells": [ 
        { 
         "label":"linkimg", 
         "links": [ 
          { 
           "name":"link1" 
          }, 
          { 
           "name":"link2" 
          } 
         ] 
        } 
        ] 
       }, 
       { 
        "id":"6", 
        "read": false, 
        "cells": [ 
        { 
         "label":"linkimg", 
         "links": [ 
          { 
           "name":"link1" 
          }, 
          { 
           "name":"link2" 
          } 
         ] 
        } 
        ] 
       }, 
       { 
        "id":"7", 
        "read": false, 
        "cells": [ 
        { 
         "label":"linkimg", 
         "links": [ 
          { 
           "name":"link1" 
          }, 
          { 
           "name":"link2" 
          } 
         ] 
        } 
        ] 
       }, 
       { 
        "id":"8", 
        "read": false, 
        "cells": [ 
        { 
         "label":"linkimg", 
         "links": [ 
          { 
           "name":"link1" 
          }, 
          { 
           "name":"link2" 
          } 
         ] 
        } 
        ] 
       }, 
       { 
        "id":"9", 
        "read": false, 
        "cells": [ 
        { 
         "label":"linkimg", 
         "links": [ 
          { 
           "name":"link1" 
          }, 
          { 
           "name":"link2" 
          } 
         ] 
        } 
        ] 
       }, 
       { 
        "id":"10", 
        "read": false, 
        "cells": [ 
        { 
         "label":"linkimg", 
         "links": [ 
          { 
           "name":"link1" 
          }, 
          { 
           "name":"link2" 
          } 
         ] 
        } 
        ] 
       }, 
       { 
        "id":"11", 
        "read": false, 
        "cells": [ 
        { 
         "label":"linkimg", 
         "links": [ 
          { 
           "name":"link1" 
          }, 
          { 
           "name":"link2" 
          } 
         ] 
        } 
        ] 
       }, 
       { 
        "id":"12", 
        "read": false, 
        "cells": [ 
        { 
         "label":"linkimg", 
         "links": [ 
          { 
           "name":"link1" 
          }, 
          { 
           "name":"link2" 
          } 
         ] 
        } 
        ] 
       }, 
       { 
        "id":"13", 
        "read": false, 
        "cells": [ 
        { 
         "label":"linkimg", 
         "links": [ 
          { 
           "name":"link1" 
          }, 
          { 
           "name":"link2" 
          } 
         ] 
        } 
        ] 
       }, 
       { 
        "id":"14", 
        "read": false, 
        "cells": [ 
        { 
         "label":"linkimg", 
         "links": [ 
          { 
           "name":"link1" 
          }, 
          { 
           "name":"link2" 
          } 
         ] 
        } 
        ] 
       }, 
       { 
        "id":"15", 
        "read": true, 
        "cells": [ 
        { 
         "label":"linkimg", 
         "links": [ 
          { 
           "name":"link1" 
          }, 
          { 
           "name":"link2" 
          } 
         ] 
        } 
        ] 
       } 
      ] 
     } 
     } 
    } 
} 

请注意:pagetotalrecords为分页的mypage之前定义。这工作。我得到Page 1 of 3, 2 of 3 and 3 of 3。但

如果我把page,为分页totalrecordsouterwrapper那么它不工作。我得到Page 0 of 3

{ 
    "mypage":{ 
     "outerwrapper":{ 
     "page":"1", 
     "total":"3", 
     "records":"15", 
     .... 
     .... 
     } 
    } 
} 

回答

1

如果你想改变你的JSON的输入数据的里面你必须通知的jqGrid关于新的地方pagetotalrecords的地方。你可以使用jsonReader来做到这一点。例如,您可以在以下jsonReader增加的jqGrid的

的参数列表
jsonReader: { 
    page: 'mypage.outerwrapper.page', 
    total: 'mypage.outerwrapper.total', 
    records: 'mypage.outerwrapper.records' 
} 
+0

能否请你帮我这个吗?我坚持这一点。 http://stackoverflow.com/questions/8618691/jqgrid-how-to-map-cell-data-to-column-model-if-column-model-is-in-json-respons – techlead 2011-12-23 19:06:03