Ember.JS中的动态计算属性已弃用?

前端之家收集整理的这篇文章主要介绍了Ember.JS中的动态计算属性已弃用?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我试图制作一个垃圾应用程序.我有一个计算属性,控制器如下所示:
  1. // The Controller
  2.  
  3. Todos.Controller = Ember.Controller.create({
  4.  
  5. // ** SNIP ** //
  6.  
  7. countCompleted: function()
  8. {
  9. return this.get('todos').filterProperty('completed',true).length
  10. }.property(),});
  11.  
  12. // The View
  13.  
  14. {{Todos.Controller.countCompleted.property}} Items Left

现在我正在关注的教程是使用旧版本的Ember.JS.我已经修复了每个错误,但是这样:

未捕获错误:断言失败:Ember.Object.create不再支持定义计算属性.

这样做的另一种方法是什么?

解决方法

计算的属性仅在对象的create()函数中被弃用.如果要创建一个计算属性,则必须先扩展()对象,然后再创建()它.

例如:

  1. // The Controller
  2.  
  3. Todos.TodosController = Ember.Controller.extend({
  4.  
  5. // ** SNIP ** //
  6.  
  7. countCompleted: function()
  8. {
  9. return this.get('todos').filterProperty('completed',});
  10.  
  11. // Note the lower case 't' here. We've made a new object
  12. Todos.todosController = Todos.TodosController.create();
  13.  
  14. // The View
  15.  
  16.  
  17. // We reference the created object here (note the lower case 't' in 'todosController')
  18. {{Todos.todosController .countCompleted.property}} Items Left

猜你在找的JavaScript相关文章