如何制作template
或partial
包含视图数据?我正在使用 Ember、车把和 requireJS。目前,我发现只outlets
包含视图数据。我正在尝试在模板中显示模型的属性。具体来说,我试图numberFive
在GraphData
. graphHolderTemplate
使用 at outlet 并不理想,因为我想在同一页面上显示来自不同视图的模板,而不管页面的 URL 是什么。
应用视图:
define(['ember', 'text!templates/applicationTemplate.html'],
function(Em, applicationTemplate) {
var ApplicationView = Em.View.extend({
// warning: template doesn't work here, even though defaultTemplate does.
defaultTemplate: Em.Handlebars.compile(applicationTemplate),
});
return ApplicationView;
});
应用模板:
<h1>{{#linkTo 'graph'}}Graph{{/linkTo}}</h1>
<h2>{{#linkTo 'graphHolder'}}Graph Holder{{/linkTo}}</h2>
<h4>outlet</h4>
{{outlet}}
<h4>template graphHolder</h4>
{{template graphHolder}}
<h4>partial graphHolder</h4>
{{partial 'graphHolder'}}
图持有人模板:
<h3>This is the graphHolder</h3>
<p>view.graphData.numberFive is: {{view.graphData.numberFive}}</p>
GraphHolderView:
define([ 'text!templates/graphHolderTemplate.html',
'controllers/GraphController',
'models/GraphData',
'ember',
], function(graphHolderTemplate, GraphController, GraphData, Em) {
// This is all that sets the template. hmmm
Em.TEMPLATES['graphHolder'] = Em.Handlebars.compile(graphHolderTemplate);
var graphData = GraphData.create();
console.log("graphData.numberFive is ": graphData.numberFive);
var GraphHolderView = Em.View.extend({
controller: GraphController,
classNames: ['hero-unit'],
graphData: GraphData.create(),
});
return GraphHolderView;
});