Given the following JSON data:
[
{
"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"
}
}
]
I'm creating a dojox/DataGrid but I can't seem to find a way to access "fields" children.
Here is the javascript:
<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>
I tried using fields.title and fields.body when defining the field, but that didn't work.
In this example, how would I access "fields" children?
You need to use the
formatter
method in the structure of the grid like below.Remember, you need to passs
_item
in thefield
, which will give you entire row in the formatter method and using dot notation, you can return the reuqired data