尝试解决Component中的弃用错误

时间:2014-09-03 03:11:44

标签: ember.js

在我的组件中,我在控制台上收到以下弃用警告:

DEPRECATION: Action handlers implemented directly on views are deprecated in favor of action handlers on an `actions` object ( action: `setVehicleModels` on <App.VehicleDetailsComponent>)

我相信这是因为我在最后一种方法中调用了@send 'setVehicleModels',但我无法弄清楚需要改变什么。 setVehicleComponent可以成为一个行动并拥有.on("init")吗?

App.VehicleDetailsComponent = Ember.Component.extend(
  setVehicleModels: (->
    model = @.get('model')
    store = App.__container__.lookup('store:main')
    store.find('automobile').then ((autos) =>
      @.set('autoModels', autos.filterBy('autoId', model.get('autoId')))
    )
    @.set('selectedModel', model)
  ).on('init')

  modelChanged: (->
    auto = @.get('selectedModel')
    @.set('model', auto)
    @.rerender()
  ).observes('selectedModel')

  updateAutoModels: (->
    @send 'setVehicleModels'
  ).observes("model")
)

完整筹码:

DEPRECATION: Action handlers implemented directly on views are deprecated in favor of action handlers on an `actions` object ( action: `setVehicleModels` on <App.VehicleDetailsComponent>)
        at Ember.CoreView.Ember.Object.extend.deprecatedSend (http://localhost:5000/assets/application.js:43617:11)
        at Ember.ActionHandler.Ember.Mixin.create.send (http://localhost:5000/assets/application.js:39742:31)
        at null.updateAutoModels (http://localhost:5000/assets/application.js:82677:19)
        at sendEvent (http://localhost:5000/assets/application.js:23928:14)
        at notifyObservers (http://localhost:5000/assets/application.js:24314:5)
        at Object.propertyDidChange (http://localhost:5000/assets/application.js:24159:3)
        at set (http://localhost:5000/assets/application.js:24392:15)
        at Ember.Observable.Ember.Mixin.create.set (http://localhost:5000/assets/application.js:33621:5)
        at null.modelChanged (http://localhost:5000/assets/application.js:82673:12) 

1 个答案:

答案 0 :(得分:1)

当您使用@.send时,它希望该函数位于actions哈希中,如果它不在哈希值中,您将获得该弃用警告。

如果您想直接从组件中调用本地函数,可以直接调用它,如@.setVehicleModels()