ionic常見緩衝處理方法

來源:互聯網
上載者:User

在實現Ionic應用上的緩衝時,遇到一些有意思的需求。 Ionic 不快取資料

要實現這個功能的話,在Ionic有一個很簡單的做法就是,直接在模板上加一個cache-view="false"

<ion-view cache-view="false" view-title="My Title!">  ....</ion-view>

這樣的話,我們就可以很簡單的實現這個功能了。但是問題來了,當我們後退的時候頁面就會特定慢——因為沒有緩衝。

這時試著尋找了別的方法,如:

$state.go($state.current, {}, {reload: true});

又或者是:

$window.location.reload(true)

但是不能像預期一樣工作。。 Ionic進入時不緩衝,後退時緩衝

於是便想了個方法,就是判斷是不是後退。如果不是的話,調用資料:

 $scope.$on("$ionicView.beforeEnter", function() {      function clearCacheForDetailPage() {        var history = $ionicHistory.forwardView();        var isLastViewCommentPages = history && history.stateName && (history.stateName === 'CommentView');        if (!isLastViewCommentPages) {          init();        }      }      clearCacheForDetailPage();    })

即,在這個時間調用init()方法,隨後在首頁清除資料:

  $scope.$on("$ionicView.beforeEnter", function() {    var clearHistoryForIndexPage = function() {      var history = $ionicHistory.forwardView();      if(history && history.stateName) {        $ionicHistory.clearHistory();      }    };    clearHistoryForIndexPage();  });
清除Angular Directive緩衝

隨後又遇到了一個有意思的問題,就是Directive是有緩衝的,這時候又要逐一修改這些Directvie:

做法大致如下:

link: function(scope, element, attrs) {    function render (value) {        //    );    render($scope.value);    scope.$watch("value",function(value) {       render(value);    }); }

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.