【发布时间】:2017-11-10 06:50:16
【问题描述】:
所以我有这个代码
init: ->
@loadRootQuestion()
methods:
loadRootQuestion: () ->
@$http.get(api_replies_path()).then(
(response) =>
@$.question = response.data.replies[0]
@loadAnswers()
)
loadAnswers: () ->
@$http.get(api_replies_path(), params: {parent_id: @$.question.id}).then(
(response) =>
@$.answers = response.data.replies
)
next: (answerId) ->
@$http.get(api_replies_path(), params: {parent_id: answerId}).then(
(response) ->
@$.question = response.data.replies[0] // I get value I need here
)
console.log(@$.question) // can't get it here
问题是在下一个方法中,范围变量无法在此承诺之外更新,我做错了什么?
更新
.modal-header
button.close type='button' ng-click='close()' data-dismiss="modal" aria-label="Close"
span
| ×
h3.modal-title
| {{ question.content }}
.modal-body
select name="answerSelect" ng-model="answer"
option ng-repeat='answer in answers' value="{{ answer.id }}"
| {{ answer.content }}
.modal-footer
button.btn.btn-primary.pull-left ng-if="showPreviousButton" ng-click="previous(question)" Prev
button.btn.btn-primary.pull-right ng-if="showNextButton" ng-click="next(answer)" Next
它与视图无关,问题值只是不想在控制器中更新
【问题讨论】: