Hallo Zusammen,
vorweg: das wird ein langer Post.
Ich beschäftige mich gerade mit TVML. Meine Grundlage bildet das Beispiel von Apple. Im Moment versuche ich die Templates zu dynamisieren:
In Index.xml.js erzeuge ich ein Array und definiere es als Attribut.
In der load Funktion vom Presenter.js lese ich das Attribut wieder aus und übergebe es an den ResourceLoader.
Alles anzeigen
Im ResourceLoader.js geht es weiter. Das Array wird zum Template Aufruf weitergereicht.
Alles anzeigen
In nun endlich im Template benutzt. Ich habe mich als Beispiel für das Compilation.xml.js entschieden.
Alles anzeigen
Anscheinend geht irgendwo auf dem Weg die Information verloren, dass es sich um ein Array handelt. Es reagiert wie ein String. Das Ergebnis habe ich als Bild angefügt. Leider fehlt mir das javascript Wissen, um mir selbst weiter zu helfen.
Wo ist der Fehler?
vorweg: das wird ein langer Post.
Ich beschäftige mich gerade mit TVML. Meine Grundlage bildet das Beispiel von Apple. Im Moment versuche ich die Templates zu dynamisieren:
In Index.xml.js erzeuge ich ein Array und definiere es als Attribut.
In der load Funktion vom Presenter.js lese ich das Attribut wieder aus und übergebe es an den ResourceLoader.
Quellcode
- load: function(event) {
- var self = this,
- ele = event.target,
- templateURL = ele.getAttribute("template"),
- presentation = ele.getAttribute("presentation");
- videoURL = ele.getAttribute("videoURL");
- args = ele.getAttribute("args");
- if (templateURL) {
- self.showLoadingIndicator(presentation);
- resourceLoader.loadResource(templateURL,
- function(resource) {
- if (resource) {
- var doc = self.makeDocument(resource);
- doc.addEventListener("select", self.load.bind(self));
- if (self[presentation] instanceof Function) {
- self[presentation].call(self, doc, ele);
- } else {
- self.defaultPresenter.call(self, doc);
- }
- }
- }, args
- );
- }
- },
Im ResourceLoader.js geht es weiter. Das Array wird zum Template Aufruf weitergereicht.
Quellcode
- ResourceLoader.prototype.loadResource = function(resource, callback, args) {
- var self = this;
- evaluateScripts([resource], function(success) {
- if (success) {
- var resource = Template.call(self, args);
- callback.call(self, resource);
- } else {
- var title = "Resource Loader Error",
- description = `There was an error attempting to load the resource '${resource}'. \n\n Please try again later.`,
- alert = createAlert(title, description);
- Presenter.removeLoadingIndicator();
- navigationDocument.presentModal(alert);
- }
- });
- }
In nun endlich im Template benutzt. Ich habe mich als Beispiel für das Compilation.xml.js entschieden.
Quellcode
- var Template = function(args) { return `<?xml version="1.0" encoding="UTF-8" ?>
- <document>
- <head>
- <style>
- .ordinalLayout {
- margin: 8 0 0 9;
- }
- .whiteButton {
- tv-tint-color: rgb(255, 255, 255);
- }
- </style>
- </head>
- <compilationTemplate theme="dark">
- <list>
- <relatedContent>
- <itemBanner>
- <heroImg src="${this.BASEURL}resources/images/italy/italy_20_square.jpg" />
- <row>
- <buttonLockup>
- <badge src="resource://button-add-alt" class="whiteButton" />
- <title>Title 1</title>
- </buttonLockup>
- <buttonLockup>
- <badge src="resource://button-rate" class="whiteButton" />
- <title>Title 2</title>
- </buttonLockup>
- <buttonLockup>
- <badge src="resource://button-more" class="whiteButton" />
- <title>Title 3</title>
- </buttonLockup>
- </row>
- </itemBanner>
- </relatedContent>
- <header>
- <title>${args}</title>
- <subtitle>Subtitle</subtitle>
- <row>
- <text>Text 1</text>
- <text>Text 2</text>
- </row>
- </header>
- <section>
- <header>
- <title>Title</title>
- </header>
- <listItemLockup>
- <ordinal minLength="2" class="ordinalLayout">1</ordinal>
- <title>${args[0]}</title>
- <subtitle>Subtitle 1</subtitle>
- <decorationLabel>Right label 1</decorationLabel>
- </listItemLockup>
- <listItemLockup>
- <ordinal minLength="2" class="ordinalLayout">2</ordinal>
- <title>${args[1]}</title>
- <subtitle>Subtitle 2</subtitle>
- <decorationLabel>Right label 2</decorationLabel>
- </listItemLockup>
- <listItemLockup>
- <ordinal minLength="2" class="ordinalLayout">3</ordinal>
- <title>Title 3</title>
- <subtitle>Subtitle 3</subtitle>
- <decorationLabel>Right label 3</decorationLabel>
- </listItemLockup>
- <listItemLockup>
- <ordinal minLength="2" class="ordinalLayout">4</ordinal>
- <title>Title 4</title>
- <subtitle>Subtitle 4</subtitle>
- <decorationLabel>Right label 4</decorationLabel>
- </listItemLockup>
- <listItemLockup>
- <ordinal minLength="2" class="ordinalLayout">5</ordinal>
- <title>Title 5</title>
- <subtitle>Subtitle 5</subtitle>
- <decorationLabel>Right label 5</decorationLabel>
- </listItemLockup>
- <listItemLockup>
- <ordinal minLength="2" class="ordinalLayout">6</ordinal>
- <title>Title 6</title>
- <subtitle>Subtitle 6</subtitle>
- <decorationLabel>Right label 6</decorationLabel>
- </listItemLockup>
- <listItemLockup>
- <ordinal minLength="2" class="ordinalLayout">7</ordinal>
- <title>Title 7</title>
- <subtitle>Subtitle 7</subtitle>
- <decorationLabel>Right label 7</decorationLabel>
- </listItemLockup>
- <listItemLockup>
- <ordinal minLength="2" class="ordinalLayout">8</ordinal>
- <title>Title 8</title>
- <subtitle>Subtitle 8</subtitle>
- <decorationLabel>Right label 8</decorationLabel>
- </listItemLockup>
- <listItemLockup>
- <ordinal minLength="2" class="ordinalLayout">9</ordinal>
- <title>Title 9</title>
- <subtitle>Subtitle 9</subtitle>
- <decorationLabel>Right label 9</decorationLabel>
- </listItemLockup>
- </section>
- </list>
- </compilationTemplate>
- </document>`
Anscheinend geht irgendwo auf dem Weg die Information verloren, dass es sich um ein Array handelt. Es reagiert wie ein String. Das Ergebnis habe ich als Bild angefügt. Leider fehlt mir das javascript Wissen, um mir selbst weiter zu helfen.
Wo ist der Fehler?