Domanda

Quindi ho questo semplice bisogno:

require(['app/'+url,'dojo/text!content/'+url], function(module,template){
        if(module.init){
                module.init({
                        container: panel, 
                        containerId: 'contentTabs_' + idOp,
                        template: template
                });
        }
});
.

Ma il modello potrebbe non essere lì (a volte lo fa).Quindi tutto ciò che accade vorrei che il mio richieda il callback da eseguire.

Qual è il modo AMD per farlo?

Grazie ragazzi.

È stato utile?

Soluzione

Invece di usare dojo/text!, scrivi il tuo plugin:

require(['foo/maybe!'+url], function(maybeTemplate) {
  if (maybeTemplate === undefined) {
    // it's there
  } else {
    // it's not there
  }
}
.

foo/maybe deve risolvere un oggetto con un membro load : function (id, require, callback).

.
load(
  id,        // the string to the right of the !
  require,   // AMD require; usually a context-sensitive require bound to the module making the plugin request
  callback   // the function the plugin should call with the return value once it is done
) -> undefined
.

È possibile utilizzare una chiamata XHR per recuperare la risorsa e risolvere su undefined su un errore 404.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top