0
使用值從模型實例我想在我的模板使用的值從我的模型實例,在PHP中我會通過執行以下去:ember.js模板
<?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全名稱值顯示?
但如果我想創建示範用戶的多個實例,爲讓說一個聊天應用程序是什麼? – xorinzor 2013-04-07 21:23:27
然後,您從'model'鉤子返回一個*數組*,並使用模板中的{{#each}} Handlebars helper遍歷它們。 – zeppelin 2013-04-07 22:15:38