2012-04-11 3 views
1

: 나는 DojoX는/데이터 그리드를 만드는거야하지만 "필드"아이들에 액세스 할 수있는 방법을 찾을 수 없습니다JSON 자식 객체/ObjectStore

[ 
{ 
    "pk": 2, 
    "model": "corkboard.announcement", 
    "fields": { 
     "body": "Test announcement 2 body.", 
     "date": "2012-04-10T00:59:12Z", 
     "title": "Test Announcement 2" 
    } 
}, 
{ 
    "pk": 1, 
    "model": "corkboard.announcement", 
    "fields": { 
     "body": "Test Announcement 1 body.", 
     "date": "2012-04-10T00:58:56Z", 
     "title": "Test Announcement 1" 
    } 
} 
] 

.

<script> 
     var announcementStore, dataStore, grid; 
     require(["dojo/store/JsonRest", "dojo/store/Memory", "dojo/store/Cache", "dojox/grid/DataGrid", "dojo/data/ObjectStore", "dojo/query", "dojo/domReady!"], 
      function(JsonRest, Memory, Cache, DataGrid, ObjectStore, query){ 
      announcementStore = Cache(JsonRest({target:"/corkboard/announcements/"}), Memory()); 
      grid = new DataGrid({ 
       store: dataStore = ObjectStore({objectStore: announcementStore}), 
       structure: [ 
        {name:"Title", field:"title", width: "200px"}, 
        {name:"Body", field:"body", width: "200px", editable: true} 
       ] 
      }, "target-node-id"); 
      grid.startup(); 
      query("#save").onclick(function(){ 
       dataStore.save(); 
      }); 
     }); 
</script> 

내가 필드를 정의 할 때 fields.title 및 fields.body를 사용했지만 문제가 해결되지 않은 : 여기

는 자바 스크립트입니다.

이 예제에서 "필드"자식은 어떻게 액세스합니까?

답변

0

아래와 같이 그리드 구조에서 formatter 메서드를 사용해야합니다.

{name:"Title",field:"_item",widht:"200px",formatter:function(item){return item.fields.title}} 

는 포맷터 방법 당신에게 전체 행을 줄 것이다 도트 표기법을 사용하여, 당신은 reuqired 데이터를 반환 할 수있는의 field_item을 passs 할 필요가 기억