Reference objects of arrays in Exhibit

120 views
Skip to first unread message

cturner

unread,
Jun 20, 2011, 4:57:53 AM6/20/11
to simile-...@googlegroups.com
Hi,

I use the following JSON file and want to reference an attribute of an object of the fileReferences array to display in my exhibit.

{
  "items": [
    {
      "id": 0,
      "name": "IDS_BLA_BLUB",
      "count": 4,
      "label": "blablub",
      "fileReferences": [
        {
          "fileName": "D:\\Development\\eclipse_workspace\\bla\SatSettings.java",
          "lineNumber": 138,
          "line": "sat.setTextId(\"IDS_BLA_BLUB\");"
        },
        {
          "fileName": "D:\\Development\\prop.ini",
          "lineNumber": 287,
          "line": "satSet: \"IDS_BLA_BLUB\""
        }
      ]
    }
  ]
}

I tried to use something like this: <div class="fileReferences"><span ex:content=".fileReferences[0].fileName"></span></div> but it didn't work. I couldn't find any examples on how to handle such references. So It would be great if somebody could help me out..

Best,
Chris


Ryan Lee

unread,
Jun 20, 2011, 6:22:55 PM6/20/11
to simile-...@googlegroups.com
Hi,

If this is a literal quote from your JSON file, you'll need to
reorganize it so the items are all flat, not nested. That is, give your
item with id: 0 a sensible value for the type: property (Text?), make
the objects that are fileReferences their own items, and give them a
separate type: value (File?) and an identifier.

Your property fileReferences should be set as having a valueType: of
"item" in a schema. See
http://simile.mit.edu/wiki/Exhibit/Getting_Started_Tutorial#Schema

Finally, fileReferences should list the Files by reference to their
identifier. Your expression would read ".fileReferences.fileName".

The core of your question appears to be about extracting one item out of
a list - but order of values is not maintained, and there is no support
for an expression syntax using information about the original ordering.
If you want just one list element, I would suggest using a different
property for the File you want to show.

{
"items": [
{
"id": 0,
"name": "IDS_BLA_BLUB",
"count": 4,
"label": "blablub"

"fileReferences": [ "SatSettings.java", "prop.ini" ]
},
{
"label": "SatSettings.java",


"fileName": "D:\\Development\\eclipse_workspace\\bla\SatSettings.java"


...

],
"properties": {
"fileReferences" : {
"valueType": "item"

cturner

unread,
Jun 21, 2011, 5:20:28 AM6/21/11
to simile-...@googlegroups.com
Hi Ryan,

thanks for your reply. I followed your advice and reordered my data into two separate files:
{
  "items": [
    {
      "id": 228,
      "label": "IDS_BLABLUB_228",
      "fileReferences": [
        "file_4975",
        "file_4976",
        "file_4977",
        "file_4978"
      ],
      "name": "IDS_BLABLUB",
      "count": 4
    },
  ],
  "properties": {
    "count": {
      "valueType": "number"
    },
    "name": {
      "valueType": "text"
    },
    "fileReferences": {
      "valueType": "item"
    }
  }

and the file reference data:
----snip----
    {
      "label": "file_4975",
      "id": 4975,
      "fileName": "D:\\Development\\blabla.java",
      "lineNumber": 39,
      "line": "currentDialogID \u003dIDS_BLABLUB"
    },
    {
      "label": "file_4976",
      "id": 4976,
      "fileName": "D:\\Development\\\blublu.java",
      "lineNumber": 130,
      "line": "case IDS_BLABLUB:"
    },
----snip----

You were right my core question was how to extract the first n elements and display them - the order of the references isn't important. But I still don't know how to do that...

Best,
Chris

Ryan Lee

unread,
Jun 21, 2011, 5:36:28 PM6/21/11
to simile-...@googlegroups.com
Hi Chris,

How's your scripting? There isn't a feature for that in Exhibit that I
know of, you'll have to implement your own solution.

If Javascript isn't your favorite, and if it's not too much work for you
to generate data, perhaps you can add a new property
fileReferencesExcerpt to your JSON generation pipeline that does the
selection of N items before Exhibit ever receives data.

Otherwise we're talking about adding a new Exhibit expression, or a new
Exhibit importer that does the selecting of N items into a new property
at load time, or a completely separate script that truncates Exhibit's
output; and I'm sure there are other possibilities.

cturner

unread,
Jun 24, 2011, 4:26:10 AM6/24/11
to simile-...@googlegroups.com
Hi Ryan,

thanks for your reply. I planned to go with the new generated data but I couldn't get it to work either... Here is what I tried:


{
  "items": [
    {
      "id": 228,
      "label": "IDS_BLABLUB_228",
      "fundstelle0":    {

         "label": "file_4975",
         "id": 4975,
         "fileName": "D:\\Development\\blabla.java",
         "lineNumber": 39,
         "line": "currentDialogID \u003dIDS_BLABLUB"
    },
    "name": "IDS_BLABLUB",
    "count": 4
    }
  ]

  "properties": {
    "count": {
      "valueType": "number"
    },
    "name": {
      "valueType": "text"
    },
    "fundstelle0": {
      "valueType": "item"
    }
  }
}
Now I try to fetch the value with: <span ex:content=".fundstelle0.fileName"></span> but it doesn't work - nothing is displayed.... sorry for the inconvenience
 

Best,
Chris

Ryan Lee

unread,
Jun 24, 2011, 2:35:49 PM6/24/11
to simile-...@googlegroups.com
Hi Chris,

One more time for the prize. Keep the flat database I suggested in my
first response. That's a hard requirement. What you excerpted below is
really no different from your original question.

The additional property I'm suggesting is in conjunction with your full
fileList property. You'd have the complete fileList and you'd also have
another property (fileListExcerpt, say) that contained just N of the
entries in the fileList.

cturner

unread,
Jun 28, 2011, 4:19:21 AM6/28/11
to simile-...@googlegroups.com
Hi Ryan,

thanks again for your help! One thing I don't understand in your first post is: How do you access the fileName property of SatSettings.java or prop.ini item?!

Best,
Johannes

Ryan Lee

unread,
Jun 30, 2011, 9:48:38 PM6/30/11
to simile-...@googlegroups.com
Referring to the mock database I drew up in my original reply,

<span ex:content=".fileReferences.fileName"></span>

which will display as a list of every item in the fileReferences value list.

Reply all
Reply to author
Forward
0 new messages