나는 여기에 간단한 것을 놓치고 있지만 다음은 작동하지 않는 것 같습니다.Emberjs의 같은 클래스에서 다른 메서드를 호출하는 방법
App.Storage = Ember.Object.extend
push: (key, data)-> #I want to call this from the loop below in pushMany
#...
#...
pushMany: (key, data)->
data.forEach (d)->
#Tried:
@push(key, d) #<< TypeError: undefined is not a function
#Also tried:
@send('push', key, d) #<< TypeError: undefined is not a function
#Also tried:
App.Storage.push(key, d) #<< TypeError: undefined is not a function
나는 경로에 pushMany를 호출 오전 :
App.MessagesRoute = Ember.Route.extend
setupController: (controller, model)->
#storage is injected to route
#I can call storage.push here so I'm pretty sure my injection is working properly
storage = @get('storage')
storage.pushMany 'message', [{id: 3, value: 'Test Msg', author: 'Jules'}, {id: 4, value: 'Hello World!', author: 'Jules'}]
이제 시간 동안 갇혀 있었다. 어떤 도움을 주시면 감사하겠습니다.
흠 ... pushMany 함수에서'data'와'key'가'function' 매개 변수 인'set'을'접근'하고'데이터'를 사용하려하지 않았습니다. 내가 액세스하고자하는 것은'pushMany' 함수 안에있을 때'push' 함수입니다. 아니면 당신이 설명하고 싶은 것을 오해 했습니까? –
내 답변에 케이스를 추가했습니다. – medokin
마술처럼 작동합니다! : D 나는'self = this'를 사용한 적이 없으며'this'는 항상 사용하기 때문에 제대로 사용하는 방법입니다. 감사! : D –