简体   繁体   English

Ember.js视图没有自动更新

[英]Ember.js view not being autoupdated

I'm stuck in the 'Scrumptious' bookmark app created in a Tuts+ Course called 'Let's Learn Ember'. 我被困在Tuts +课程中创建的'Scrumptious'书签应用程序中,名为'Let's Learn Ember'。 As the course is some months old, I'm trying to re-do the app using the most updated versions of Ember.js and Ember-Data. 由于课程已有几个月的历史,我正在尝试使用最新版本的Ember.js和Ember-Data重新制作应用程序。

Here's the repo : https://github.com/jantequera/scrumptious 这是回购https//github.com/jantequera/scrumptious

NOTE : due to @claptimes request, I've added a jsbin of the project: http://jsbin.com/ukuDORUZ/2/edit?html,js,console 注意 :由于@claptimes请求,我添加了项目的jsbin: http ://jsbin.com/ukuDORUZ/2/edit?html,js,console

The thing is, that in the 'bookmarks' template, when I add a new bookmark, it is stored and the "create Bookmark" partial disappears, but the bookmarks table isn't updated, and it doesn't even reflect the changes in the newly created bookmark on real-time, which is the intended behaviour. 问题是,在“书签”模板中,当我添加新书签时,它会被存储并且“创建书签”部分消失,但书签表不会更新,甚至不会反映出实时新创建的书签,这是预期的行为。 In other words, I have to refresh the browser in order to see the new bookmark in the table, which is not the way an ember.js app should work. 换句话说,我必须刷新浏览器才能看到表中的新书签,这不是ember.js应用程序的工作方式。

As I am learning Ember, I might have missed or misunderstood something in the guides that explains this, so any help is welcome. 当我正在学习Ember时,我可能错过或误解了指南中解释这一点的内容,所以欢迎任何帮助。 Below I expose the code, if you wish to see it in context or even try it out, use the repo above. 下面我公开代码,如果你想在上下文中看到它或者甚至尝试它,请使用上面的repo。 Thanks! 谢谢!

EDIT Anton below pointed out and advised the usage of components, which make the jsfiddle above work. EDIT Anton在下面指出并建议使用组件,这使得上面的jsfiddle工作。 However, when I use this solution in my local copy, it wouldn't work UNLESS I use the FixtureAdapter INSTEAD of the LSAdapter (local-storage). 但是,当我在本地副本中使用此解决方案时,它将无法工作, 除非我使用LSAdapter的FixtureAdapter INSTEAD(本地存储)。 Any clue? 任何线索?

http://jsbin.com/ukuDORUZ/6 http://jsbin.com/ukuDORUZ/6

You use "render" helper: 你使用“渲染”助手:

{{render "table" controller.regular}}

model is not updated in "table" template when you create new bookmark and update controller.regular 创建新书签并更新controller.regular时,“table”模板中的模型不会更新

you can use component ( http://emberjs.com/guides/components/ ) and bind your model to component's parameter: 您可以使用组件( http://emberjs.com/guides/components/ )并将模型绑定到组件的参数:

{{bookmarks-table elementsBinding="controller.regular"}}

http://jsbin.com/ukuDORUZ/6 http://jsbin.com/ukuDORUZ/6

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM