我想在我的模板中使用我的模型实例中的值,在 PHP 中我会执行以下操作:
<?php
class User {
private $name;
public function __construct($name) {
$this->name = $name;
}
public function getName() {
return $this->name;
}
}
$localuser = new User("john doe");
?>
<p>My name is: <?= $localuser->getName(); ?></p>
但是我如何在 Ember.js 中做到这一点?还是我误解了 Ember.js 的 MVC 模型?
这是我用于创建 localuser 实例的 Ember.js 代码:
Example = Ember.Application.create();
Example.User = Example.Object.extend({
firstname: null,
lastname: null,
network: null,
fullName: function() {
return this.get('firstName') + " " + this.get('lastName');
}.property('firstName', 'lastName')
});
Example.LocalUser = Example.User.create({
firstname: "John",
lastname: "Doe"
});
Example.IndexRoute = Ember.Route.extend({
setupController: function(controller) {
},
renderTemplate: function() {
this.render("exampleTemplate");
}
});
and my HTML template (which doesn't work):
<script type="text/x-handlebars" data-template-name="exampleTemplate">
{{#model Example.LocalUser}}
{{fullName}}
{{/model}}
</script>
我需要在模板中添加什么才能从 Example.LocalUser 中获取全名值以显示?