gpt4 book ai didi

javascript - Emberjs - 实时更改不起作用?

转载 作者:行者123 更新时间:2023-11-29 10:46:40 24 4
gpt4 key购买 nike

我遵循了 Emberjs 的创建者之一的教程:http://www.youtube.com/watch?v=Ga99hMi7wfY本教程的目标是通过示例介绍 emberjs 的基础知识,其中有一个帖子列表,如果您编辑一个帖子,内容将映射到相应的文本区域或文本字段。然后,更改是实时可见的。

然而,这不起作用。而且我一直在关注官方教程(显然,自从这个 yt 视频以来,emberjs 已经发生了很大变化)。

无论如何,我错过了什么?

这是我的代码(HTML):

  <script type="text/x-handlebars">
<div class="navbar">
<div class="navbar-inner">
<a class="brand" href="#">Bloggr</a>
<ul class="nav">
<li>{{#linkTo 'posts'}}Posts{{/linkTo}}</li>
<li>{{#linkTo 'about'}}About{{/linkTo}}</li>
</ul>
</div>

{{outlet}}
</div>
</script>

<script type="text/x-handlebars" id="about">
<div class="about">
random text about
</div>
</script>

<script type="text/x-handlebars" id="posts">

{{#if isEditing}}
{{partial 'post/edit'}}
<button {{action 'save'}}>Done</button>
{{else}}
<button {{action 'edit'}}>Edit</button>
{{/if}}
<div class="about">
<table>
<tr>
<th>Id</th>
<th>Title</th>
<th>Author</th>
<th>Date</th>
<th>Utilities</th>
</tr>
{{#each model}}
<tr>
<td>{{id}}</td>
<td>{{title}}</td>
<td>{{author}}</td>
<td>{{publishedAt}}</td>
<td>{{#linkTo "post" this}}Details{{/linkTo}}</td>
</tr>
{{/each}}
</table>
</div>
<div>
{{outlet}}
</div>
</script>

<script type="text/x-handlebars" id="post/_edit">
<p>{{view Ember.TextArea valueBinding="title" placeholder="test.."}}</p>
<p>{{view Ember.TextField valueBinding="author"}}</p>
</script>

<script type="text/x-handlebars" id="post">
<h1>{{title}}</h1>
<h2>by {{author}}</h2>
<small>{{date publishedAt}}</small>
</script>

这是 emberjs 部分:

    App = Ember.Application.create();

App.Store = DS.Store.extend({
revision: 12,
adapter: 'DS.FixtureAdapter'
});

App.Router.map(function(){
this.resource("posts", function(){
this.resource("post", { path: ':post_id'});
});
this.resource("about");
});

App.PostsRoute = Ember.Route.extend({
model: function(){
return App.Post.find();
}
});

App.PostsController = Ember.ObjectController.extend({
isEditing: false,
edit: function(){
this.set("isEditing", true);
},
save: function() {
this.set("isEditing", false);
}
});

App.Post = DS.Model.extend({
title: DS.attr('string'),
author: DS.attr('string'),
publishedAt: DS.attr('date')
});

App.Post.FIXTURES = [
{
id:1,
title: "This is my title",
author: "John Doe",
publishedAt: new Date('12-27-2012')
},
{
id:2,
title: "This is another title",
author: "Jane Doe",
publishedAt: new Date('02-03-2013')
}
];

Ember.Handlebars.registerBoundHelper('date', function(date){
return date.getFullYear();
});

最佳答案

Controller 的名称应该是 PostController 而不是 PostsController。他们负责处理不同的路线。

关于javascript - Emberjs - 实时更改不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18167661/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com