2013-10-22 57 views
0
[ 
    { 
    "Address": { 
     "Address": "4 Selby Road\nHowden", 
     "AddressId": "1414449", 
     "AddressLine1": "4 Selby Road", 
     "AddressLine2": "Howden", 
     "ContactId": "14248844", 
     "County": "North Humberside", 
     "Country": "UK", 
     "Postcode": "DN14 7JW", 
     "Town": "GOOLE", 
     "FullAddress": "4 Selby Road\nHowden\r\nGOOLE\r\nNorth Humberside\r\nDN14 7JW\r\nUnited Kingdom" 
    }, 
    "ContactId": 14248844, 
    "Title": "Mrs", 
    "FirstName": "", 
    "Surname": "Neild", 
    "FullName": " Neild", 
    "PostCode": "DN14 7JW" 
    }, 
    { 
    "Address": { 
     "Address": "466 Manchester Road\nBlackrod", 
     "AddressId": "1669615", 
     "AddressLine1": "466 Manchester Road", 
     "AddressLine2": "Blackrod", 
     "ContactId": "16721687", 
     "County": "", 
     "Country": "UK", 
     "Postcode": "BL6 5SU", 
     "Town": "BOLTON", 
     "FullAddress": "466 Manchester Road\nBlackrod\r\nBOLTON\r\nBL6 5SU\r\nUnited Kingdom" 
    }, 
    "ContactId": 16721687, 
    "Title": "Miss", 
    "FirstName": "Andrea", 
    "Surname": "Neild", 
    "FullName": "Andrea Neild", 
    "PostCode": "BL6 5SU" 
    }, 
    { 
    "Address": { 
     "Address": "5 Prospect Vale\nHeald Green", 
     "AddressId": "2127294", 
     "AddressLine1": "5 Prospect Vale", 
     "AddressLine2": "Heald Green", 
     "ContactId": "21178752", 
     "County": "Cheshire", 
     "Country": "UK", 
     "Postcode": "SK8 3RJ", 
     "Town": "CHEADLE", 
     "FullAddress": "5 Prospect Vale\nHeald Green\r\nCHEADLE\r\nCheshire\r\nSK8 3RJ\r\nUnited Kingdom" 
    }, 
    "ContactId": 21178752, 
    "Title": "Mrs", 
    "FirstName": "", 
    "Surname": "Neild", 
    "FullName": " Neild", 
    "PostCode": "SK8 3RJ" 
    } 
] 

我試圖找回以上JSON jQuery中,如下(稱爲data):jQuery的多級JSON數據陣列

var source = 
    { 
     localdata: data, 
     sort: customsortfunc, 
     datafields: 
     [ 
      { name: 'Surname', type: 'string' }, 
      { name: 'FirstName', type: 'string' }, 
      { name: 'Title', type: 'string' }, 
      { name: 'Address.Address', type: 'string' } 

     ], 
     datatype: "array" 
    }; 
    var dataAdapter = new $.jqx.dataAdapter(source); 

    $("#jqxgrid").jqxGrid(
     { 
      width: 670, 
      source: dataAdapter, 
      theme: theme, 
      sortable: true, 
      pageable: true, 
      autoheight: true, 
      ready: function() { 
       $("#jqxgrid").jqxGrid('sortby', 'FirstName', 'asc'); 
      }, 
      columns: [ 
       { text: 'Title', datafield: 'Title', width: 100 }, 
       { text: 'First Name', datafield: 'FirstName', width: 100 }, 
       { text: 'Last Name', datafield: 'Surname', width: 100 }, 
       { text: 'Address', datafield: 'Address.Address', width: 100 }, 

      ] 
     }); 

唯一的問題是沒有任何顯示的"Address.Adress"。任何人都可以提醒我嗎?

+0

只是一個預感,但嘗試''數據字段:'地址[「地址」]''' – Kippie

+0

你可能需要將該對象扁平化到插件所期望的。另外,我在你的問題中看不到json。 –

+0

@Kippie,我試過了。它沒有工作。 – Tun

回答

0

在將對象數組傳遞到網格之前展平對象數組。

localdata: $.map(data,function(obj){ 
    return $.extend(obj,{ 
     Address: obj.Address.Address 
    }); 
}), 

現在,你可以簡單地使用"Address"而不是"Address.Address"

2

我一點兒也不熟悉,你是在這裏使用,但是看着在this頁面信息的插件,我相信這是一個問題使用了錯誤的mapChar

您需要使用Address>Address或在您的選項中指定不同的mapChar並將其設置爲'.'

希望這會有所幫助。