2012-06-29 2 views
1

이 코드의 문제점은 무엇입니까? 나는 내 json을 얻을 수 있고 경고 (예 : xhr과 함께 작동합니다)를 디버깅 할 수 있습니다 ... 예를 들어,이 함수 내에서 (xhr), alert (data [0] .name) 값. Web에는 그다지 많은 예제가 없습니다 ...하지만 열을 지정하고 객체 저장소를 추가해도 아무 것도 표시되지 않습니다 ... 기본적으로 json 파일 (로컬)을로드하고 그리드에 렌더링하려고하지만 결국 내 응용 프로그램 내에서 CRUD를 처리하기 위해 REST를 사용할 것입니다 (그래서 JsonRest를 조만간 사용하게 될 것입니다).ObjectStore (로컬 json)가있는 Dojo OnDemandGrid (dgrid)

나는 AJAX 와도 관련이 있다고 생각한다. 아마도 나는 sync를 true로 설정해야한다. (내 전역 변수는 보이지 않기 때문에 ... 제대로 정의되지 않았다.)

define([ 
    "dojo/_base/declare", 
    "dijit/_WidgetBase", 
    "dgrid/OnDemandGrid", 
    "dojo/_base/xhr", 
    "dojo/store/Memory", 
    "dojo/data/ObjectStore", 
    "dgrid/Keyboard", 
    "dgrid/Selection" 
], function(
    declare, 
    _WidgetBase, 
    Grid, 
    xhr, 
    Memory, 
    ObjectStore, 
    Keyboard, 
    Selection 
){ 
    var dataStore; 

    xhr.get({ 
     url: "app/resources/data/content.json", 
     handleAs: "json" 
    }).then(function(data){ 
    dataStore = new ObjectStore({ objectStore:new Memory({ data: data.items }) }); 
    }); 

    return declare([_WidgetBase, Grid, Keyboard, Selection], { 
    store: dataStore, 
    columns:{ 
      name: { label: "name" }, 
      autodelete: { label: "autodelete" }, 
      groupe_id: { label: "groupe_id" }, 
      global: { label: "global" }, 
      date: { label: "date" }, 
      duree: { label: "duree" }, 
      description: { label: "description" }, 
      fichier: { label: "fichier" }, 
      pleinecran: { label: "pleinecran" }, 
      repertoire: { label: "repertoire" }, 
      taille: { label: "taille" }, 
      expiration: { label: "expiration" }, 
      id: { label: "id" }, 
      catergorie: { label: "catergorie" }, 
      brouillon: { label: "brouillon" } 
     }, 

    postCreate: function() { 
    } 
}); 
}); 

답변

1

어떤 이유로 든 objectStore를 저장소에 전달할 수 없습니다 (dgrid-onDemandGrid의 경우). 이번에는 "데이터 모델"과 뷰어를 분리했습니다. 그래서, (예를 들어, 내 코드가 꽤 모듈 형) 응용 프로그램/모델이있다 : 마지막으로

define([ 
    "dojo/_base/xhr", 
    "dojo/store/Memory", 
    "dojo/store/Observable"], 
function(
    xhr, 
    Memory, 
    Observable 
){ 

    xhr.get({ 
     url: "app/resources/data/content.json", 
     handleAs: "json", 
     sync: true, 
    }).then(function(data){ 
     contentStore = Observable(Memory({data: data})); 
    }); 

    // global var "song_store" 
    return contentStore; 
}); 

, 나는 그것을 (응용 프로그램/UI/레이아웃/ContentGrid)에 내 가게를 부착하여이 같은 내 격자를 생성 .

define([ 
    "dojo/_base/declare", 
    "dijit/_WidgetBase", 
    "dgrid/OnDemandGrid", 
    "dgrid/Keyboard", 
    "dgrid/Selection", 
    "dgrid/extensions/ColumnHider", 
    "dgrid/editor", 
    "app/models/content" 
], function(
    declare, 
    _WidgetBase, 
    Grid, 
    xhr, 
    Memory, 
    ObjectStore, 
    Keyboard, 
    Selection, 
    Hider, 
    editor 
){ 

    return declare([Grid, Keyboard, Selection, Hider], { 
     store: contentStore, 
     /*columns: { 
      selected: editor({ 
        label: " ", 
        autoSave: true, 
        sortable: false 
       }, "checkbox"), 
      Name: "Name", 
      Time: "Duration", 
      Year: "Year", 
      Artist: "Artist", 
      Album: "Album", 
      Genre: "Genre" 
     },*/ 

    columns: { 
     selected: editor({ 
        label: " ", 
        autoSave: true, 
        sortable: false 
       }, "checkbox"), 
     nom: "Name", 
     autodelete: "Auto-delete", 
     groupe_id: "Groupe ID", 
     global: "Global", 
     date: "Date", 
     duree: "Lenght", 
     description: "Description", 
     fichier: "Filename", 
     pleinecran: "Fullscreen", 
     repertoire: "Folder", 
     taille: "Size", 
     expiration: "Expired", 
     id: "id", 
     catergorie: "Category", 
     brouillon: "Example" 
    }, 

    }); 
}); 
관련 문제