1

我是 Onsen UI 的新手。我应该如何使用“返回”方法返回主页?(就像左后退按钮一样。)我尝试使用 pushPage-Method 来做到这一点。它有效,但动画不同。

带有后退/保存按钮的模板的 HTML

<ons-navigator var="profileNavigator">
<ons-list ng-repeat="item in profileData">
<ons-list-item modifier="chevron" class="profile-list-item-container" ng-click="openAboutMeDesc(item.aboutMe)">
      <div class="profile-list-item-left">
        <i class="fa fa-child fa-profile-list"></i>
      </div>
      <div class="profile-list-item-right">
        <div class="profile-list-item-content">
          <div class="profile-category">Über mich
          </div>

          <span class="profile-desc">{{item.aboutMe}}</span>
        </div>
      </div>
    </ons-list-item>

<ons-template id="profile-aboutme-desc.html">
<ons-page>
      <ons-toolbar>
        <div class="left">
        <ons-back-button>Back</ons-back-button>
        </div>
        <div class="right">
        <ons-toolbar-button ng-click="saveAboutMeDesc(item.naboutMe)">Save</ons-toolbar-button></div>
        <div class="center">About</div>
      </ons-toolbar>
      <ons-row>
      <!--my content-->           
      </ons-row>    
</ons-page>     
</ons-template>
</ons-navigator>

JavaScript

$scope.openAboutMeDesc = function (aboutMe) {
            profileNavigator.pushPage('profile-aboutme-desc.html', { animation : 'slide' } );
        }; 

$scope.saveAboutMeDesc = function (naboutMe) {

};
4

1 回答 1

2

动画是不同的(向前而不是向后),因为使用profileNavigator.pushPage方法,您正在将新页面添加到堆栈而不是返回到旧页面。如果需要进入主页面,可以考虑使用profileNavigator.resetToPage方法。

$scope.openAboutMeDesc = function (aboutMe) {
  profileNavigator.resetToPage('profile-aboutme-desc.html', { animation : 'slide' } );
}; 

请记住,您可以在“slide”、“simpleslide”、“lift”、“fade”和“none”之间选择交易动画。

如果有不清楚的地方看一下官方文档:

https://onsen.io/reference/ons-navigator.html

希望能帮助到你!

于 2015-12-30T13:56:08.520 回答