Das Notes Forum

Domino 9 und frühere Versionen => ND8: Entwicklung => Thema gestartet von: Binser am 19.07.10 - 17:16:00

Titel: Dojo + JSON/XML Kenntnisse?
Beitrag von: Binser am 19.07.10 - 17:16:00
Hallo zusammen,

wollte fragen ob jemand von euch zufällig Kenntnisse in Sachen Dojo besitzt? Speziell gehts drum, ein dojox.grid.DataGrid zu basteln mit Hilfe von JSON oder XML (von Domino Ansichten).

Liebe Grüße,
Markus
Titel: Re: Dojo + JSON/XML Kenntnisse?
Beitrag von: m3 am 19.07.10 - 17:22:05
Sicher.
Titel: Re: Dojo + JSON/XML Kenntnisse?
Beitrag von: Binser am 19.07.10 - 17:37:16
ok also etwas genauer... ein XML Stream von einer Standard Domino Ansicht (?ReadViewEntries) sieht ja z.B. so aus:
Code
<viewentries timestamp="20100719T152910,65Z" toplevelentries="3"> 
	<viewentry position="1" unid="7640ED7B76376A7EC12577650054EF56" noteid="8F6" siblings="3"> 
		<entrydata columnnumber="0" name="Feld01"> 
		<text>Doc01 - Wert01</text></entrydata> 
		<entrydata columnnumber="1" name="Feld02"> 
		<text>Doc01 - Wert02</text></entrydata> 
	</viewentry> 
	<viewentry position="2" unid="7EE2AFCFDB3F29AEC12577650054F6FC" noteid="8FA" siblings="3"> 
		<entrydata columnnumber="0" name="Feld01"> 
		<text>Doc02 - Wert01</text></entrydata> 
		<entrydata columnnumber="1" name="Feld02"> 
		<text>Doc02 - Wert02</text></entrydata> 
	</viewentry> 
	<viewentry position="3" unid="8A1A2B368EEC3369C12577650054FC46" noteid="8FE" siblings="3"> 
		<entrydata columnnumber="0" name="Feld01"> 
		<text>Doc03 - Wert01</text></entrydata> 
		<entrydata columnnumber="1" name="Feld02"> 
		<text>Doc03 - Wert02</text></entrydata> 
	</viewentry> 
</viewentries>


Ein normaler XML-Stream ohne Attribute wie z.B.
Code
<books> 
	<book> 
		<isbn>1</isbn> 
		<title>Title of 1</title> 
		<author>Author of 1</author> 
	</book>
</books>
bekomm ich ohne Probleme eingelesen. Nur wie siehts mit den Attributen aus? Habe nach ein paar Anwendungsbeispielen gesucht, wie man die Attribute mappen kann (attributeMap:{}) jedoch leider nichts genaues.


Hast du evtl. ein kleines Beispiel da, wie du das bei dir machst? :-/

Liebe Grüße,
Markus
Titel: Re: Dojo + JSON/XML Kenntnisse?
Beitrag von: pram am 19.07.10 - 23:22:28
Kennst du ?ReadViewEntries&OutputFormat=JSON
(geht ab 8 oder 8.5)

Gruß
Roland
Titel: Re: Dojo + JSON/XML Kenntnisse?
Beitrag von: Binser am 20.07.10 - 08:52:29
Hallo Roland,

mit JSON hab ich es auch schon versucht... besteht eigentlich genau das selbe Problem, also das definieren von Layouts in Dojo :-/

Trotzdem danke!

Lg,
Markus
Titel: Re: Dojo + JSON/XML Kenntnisse?
Beitrag von: atbits am 20.07.10 - 09:23:48
Und was war jetzt das Problem, schickt doch mal dein JS
\lg david
Titel: Re: Dojo + JSON/XML Kenntnisse?
Beitrag von: Binser am 20.07.10 - 10:15:42
Ok... also folgender Code funktioniert wenn ich den JSON-Code einer Ansicht entsprechend anpasse und in einer Datei anpasse:
Code
<html> 
<head> 
	<title>Dojo</title> 
  <style type="text/css">
		@import "dojo/resources/dojo.css";
		@import "dojox/grid/resources/Grid.css";
		@import "dojox/grid/resources/tundraGrid.css";
		.grid {
			width: 70em;
			height: 15em;
		}
	</style>
  
	<script type="text/javascript"
		src="dojo/dojo.js" djConfig="isDebug:true, parseOnLoad: true">
	</script> 
	<script type="text/javascript">
		dojo.require("dojox.grid.DataGrid");
		dojo.require("dojo.data.ItemFileReadStore");
		dojo.require("dojo.parser");
		
		var jsonStore = new dojo.data.ItemFileReadStore({url: "view.json"});
	</script>
</head> 
<body class="tundra"> 

<table  id="gridNode" jsId="grid" dojoType="dojox.grid.DataGrid"
           query="{ noteid: '*' }" store="jsonStore">
        <thead>
                <tr>
                        <th field="unid">Note-ID</th>
                </tr>
        </thead>
</table>

</body> 
</html>

Überarbeiteter JSON-Code der Ansicht:
Code
{ "@timestamp" : "20100719T131752,62Z",
  "@toplevelentries" : "6",
  "items" : [ { "noteid" : "95E",
        "@position" : "1",
        "@siblings" : "6",
        "unid" : "C125775300255388C125775F0020E5E1",
        "entrydata" : [ { "@columnnumber" : "0",
              "@name" : "Subject",
              "text" : { "0" : "--- Private Entry ---" }
            } ]
      },
      { "noteid" : "962",
        "@position" : "2",
        "@siblings" : "6",
        "unid" : "C125775300255388C125775F0029B14C",
        "entrydata" : [ { "@columnnumber" : "0",
              "@name" : "Subject",
              "text" : { "0" : "Eintrag 001" }
            } ]
      }
    ]
}



Den Code der Ansicht musste ich entsprechend anpassen. Hier der originale
Code
{ "@timestamp" : "20100719T131752,62Z",
  "@toplevelentries" : "6",
  "viewentry" : [ { "@noteid" : "95E",
        "@position" : "1",
        "@siblings" : "6",
        "@unid" : "C125775300255388C125775F0020E5E1",
        "entrydata" : [ { "@columnnumber" : "0",
              "@name" : "Subject",
              "text" : { "0" : "--- Private Entry ---" }
            } ]
      },
      { "@noteid" : "962",
        "@position" : "2",
        "@siblings" : "6",
        "@unid" : "C125775300255388C125775F0029B14C",
        "entrydata" : [ { "@columnnumber" : "0",
              "@name" : "Subject",
              "text" : { "0" : "Eintrag 001" }
            } ]
      }
    ]
}



Wie man sieht, musste ich einmal "viewentry" in "items" umbenennen sowie die @-Zeichen davor entfernen, damit der query in dojo funktionierte.
Meine Frage ist nun, wie ich einmal mit den @-Zeichen umgehe und wie ich dojo sagen kann, dass der nicht auf die "items" gehen soll wie in allen anderen JSON-Outputs sondern auf die "viewentrys".

Hoffe ihr versteht mein Problem...


Liebe Grüße,
Markus
Titel: Re: Dojo + JSON/XML Kenntnisse?
Beitrag von: atbits am 20.07.10 - 10:24:01
Naja der ItemFileReadStore erwartet eben genau dieses JSAON Format.

siehe

http://docs.dojocampus.org/dojo/data/ItemFileReadStore

ABER:
Zitat
Custom Types

As mentioned in the Item Structure section, custom types are possible to create and use as values of attributes with this store. The caveat is, you have to tell the store, through a typeMap object, how to deserialize the cutom type value back into its object form. This is not as difficult as it first may sound. Below is the general structure information for creating a custom type map. There is a general format for all cases, and a compact format when the value can be directly used as a constructor argument.

Note: You can mix simplified form type maps with general case type maps in the same type map object. Therefore, you can use whatever is the easiest representation required to handle the custom object construction.

Note: dojo.data.ItemFileReadStore implements a custom type map for JavaScript Date already. It uses the ISO-8601 serialization format for dates to keep it consistent with other date operations in dojo. If you wish to see how ItemFileReadStore defines it, refer to the source of dojo/data/ItemFileReadStore.js. The type mapping occurs in the constructor function.

Du kannst also Mapping funktionen schreiben ;-)
\lg david
Titel: Re: Dojo + JSON/XML Kenntnisse?
Beitrag von: Binser am 20.07.10 - 10:28:09
Ah, hab ich mir schon iwie fast gedacht. Danke schon mal für die Antwort.

Du hast nicht zufällig ein kleines Beispiel für eine Mapping-Funktion? :)

Lg,
Markus
Titel: Re: Dojo + JSON/XML Kenntnisse?
Beitrag von: atbits am 20.07.10 - 10:31:25
Doch , sind doch auch beim Link dabei

Code
{
  "Date": {
    type: Date,
    deserialize: function(value){
      return dojo.date.stamp.fromISOString(value);
    }
  }
}

Selbst gemacht hab ich das aber noch nicht wenn Du das meinst ;-)
Titel: Re: Dojo + JSON/XML Kenntnisse?
Beitrag von: Binser am 20.07.10 - 10:49:31
Ok danke.

Werd mein Glück mal am Wochenende versuchen :-)

Lg,
Markus