Sto provando a dividere i miei modelli di manubri ember.js in diversi file, al fine di rendere il codice base più gestibile.Utilizzo di manubri grunt insieme a ember, per dividere i modelli in file separati
Dal momento che stiamo usando yeoman/grunt, ho trovato this handlebars plugin. L'ho configurato come segue:
handlebars: {
compile: {
options: {
namespace: 'JST'
},
files: {
'<%= yeoman.dist %>/scripts/templates.js': [
'<%= yeoman.app %>/templates/*.hbs'
],
}
}
}
Come suggerito nella sezione "Esempi di utilizzo" del plug-in. Funziona come previsto, generando un file dist/scripts/templates.js
. Ma mettere i modelli nello spazio dei nomi 'JST' li rende non più accessibili a Ember. Questo è l'errore che sto ottenendo:
Uncaught Error: assertion failed: You specified the templateName application for <App.ApplicationView:ember312>, but it did not exist.
Alcune domande:
- Come faccio a "inizializzare" i modelli di manubrio, che sono in questo momento in
templates.js
, in modo che Ember può trovarli? - Come posso dire a dove e dove collocare i modelli nel DOM, poiché i modelli sono ora fuori dal corpo del documento?
Questo è il mio index.html:
<!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
<head>
<meta charset="utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
<title></title>
<meta name="description" content=""/>
<meta name="viewport" content="width=device-width"/>
<!-- build:css styles/main.css -->
<link rel="stylesheet" href="styles/bootstrap.min.css"/>
<link rel="stylesheet" href="styles/css/font-awesome.min.css"/>
<link rel="stylesheet" href="styles/font-styles.css"/>
<link rel="stylesheet" href="styles/main.css"/>
<!-- endbuild -->
</head>
<body>
<!--[if lt IE 7]>
<p class="chromeframe">You are using an outdated browser. <a href="http://browsehappy.com/">Upgrade your browser today</a> or <a href="http://www.google.com/chromeframe/?redirect=true">install Google Chrome Frame</a> to better experience this site.</p>
<![endif]-->
<!-- Add your site or application content here -->
<!-- My templates used to be here, but now they are in templates.js -->
<div class="pagination">
<ul>
<li><a href="#">Prev</a></li>
<li><a href="#">1</a></li>
<li><a href="#">2</a></li>
<li><a href="#">3</a></li>
<li><a href="#">4</a></li>
<li><a href="#">Next</a></li>
</ul>
</div>
</script>
<!-- build:js scripts/scripts.js -->
<script src="scripts/vendor/jquery-1.9.1.js"></script>
<script src="scripts/vendor/handlebars.1.0.rc.3.js"></script>
<script src="scripts/vendor/ember-1.0.0-rc.2.js"></script>
<script src="scripts/vendor/ember-data.js"></script>
<script src="scripts/vendor/bootstrap.min.js"></script>
<script src="scripts/templates.js"></script>
<script src="scripts/main.js"></script>
<!-- endbuild -->
</body>
</html>
solo curioso-qual è il tuo back-end? –