Ionic(v1)应用程序使用listView和PouchDb

时间:2018-01-05 21:32:06

标签: javascript android ios angularjs ionic-framework

在我的Ionic应用程序中,有一个带有卡片的listView,用户可以点击它。点击后,他们应该看到一个包含更多细节的页面。所有内容都在pouchDB数据库中(也在Firebase中远程)。生成此列表的代码如下:

        <div class="card" ng-repeat="challenge in vm.challenges track by $index" ng-class="{'bounceInLeft': $index % 2 !== 0, 'bounceInRight': $index % 2 === 0}" ng-click="vm.goToChallenge(challenge)">
        <div class="item item-text-wrap">
            <div class="resource">
                <img ng-src="{{ challenge.resources[0].image }}" ng-attr-alt="{{ challenge.resources[0].caption }}" ng-srcset="{{ challenge.resources[0].srcset }}" ng-if="challenge.resources && challenge.resources[0].type === 'img'">
                <img ng-src="{{ challenge.resources[0].url | getYouTubeImage }}" ng-attr-alt="{{ challenge.resources[0].caption }}" ng-if="challenge.resources && challenge.resources[0].type === 'video'">
                <i class="ion-play" ng-if="challenge.resources && challenge.resources[0].type === 'video'"></i>
            </div>
            <p class="category">{{ challenge.categoryName }}</p>
            <p class="name">{{ challenge.name }}</p>
        </div>
        <div class="item footer item-divider">
            <div class="row">
                <div class="col col-50">
                    <i class="ion-calendar"></i> {{ challenge.seasonsObjects.join(', ') }}
                </div>
                <div class="col col-50">
                    <div>
                        <i class="ion-bookmark" ng-repeat="bookmark in (challenge.ranking + 1) | range track by $index"></i>
                    </div>
                    {{ challenge.rankingName }}
                </div>
            </div>
        </div>
    </div>

不幸的是,在iPhone 5(iOS 10.2)和三星Galaxy S4 Mini(Android 4.4)上点击一张卡并没有显示该卡的详细信息(见下图)。在iPhone 5s和三星Galaxy S4(Android 5)上,这可以正常工作(见下面的第二张图片)。 Empty screen - Details not shown

Working example

goToChallenge函数在控制器中定义如下:

vm.goToChallenge = (challenge) => {
    NavigationService.go('home.challenge', {
        challenge: challenge._id
    });
};

NavigationService具有以下代码:

angular.module('starter').factory('NavigationService', ['$window', '$q', 'ionic', '$state', '$ionicHistory', '$ionicLoading', '$ionicPopup', '$cordovaNativeAudio', '$cordovaSocialSharing', '$cordovaNetwork', '$ionicSideMenuDelegate', '$ionicNavBarDelegate', '$ionicTabsDelegate', NavigationService]);

function NavigationService($window, $q, ionic, $state, $ionicHistory, $ionicLoading, $ionicPopup, $cordovaNativeAudio, $cordovaSocialSharing, $cordovaNetwork, $ionicSideMenuDelegate, $ionicNavBarDelegate, $ionicTabsDelegate) {
let factory = {};
// Set root of history stack to the registration page with historyRoot: true
// Disable animation from slider to registration page to avoid weird transition
// in wich the header bar pops down. This is because we do not have a header bar in the slider
factory.setRootAndGo = (state, params = {}) => {
    $ionicHistory.nextViewOptions({
        historyRoot: true,
        disableAnimate: true
    });
    factory.go(state, params);
};
factory.go = (state, params = {}) => {
    $state.go(state, params, {
        location: 'replace',
        reload: true
    });
};
factory.replace = (state, params = {}) => {
    $ionicHistory.currentView($ionicHistory.backView());
    factory.go(state, params);
};
factory.toggleMenu = () => $ionicSideMenuDelegate.toggleRight();
factory.showTabs = () => {
    $ionicTabsDelegate.showBar(true);
};
factory.hideTabs = () => {
    $ionicTabsDelegate.showBar(false);
};
factory.setTitle = (title) => $ionicNavBarDelegate.title(title);
factory.getParams = () => $state.params;
factory.getNavHistory = () => $ionicHistory.viewHistory();
factory.showLoading = (options) => $ionicLoading.show(options);
factory.hideLoading = () => $ionicLoading.hide();
factory.isWebView = () => ionic.Platform.isWebView();
factory.isOffline = () => factory.isWebView() && $cordovaNetwork.isOffline();
factory.goToWebPage = (url) => $window.open(url, '_system');
factory.shareFacebook = (text, img, url) => {
    let defer = $q.defer();
    $cordovaSocialSharing.shareViaFacebook(text, img, url)
        .then(defer.resolve, defer.reject);
    return defer.promise;
};
factory.shareTwitter = (text, img, url) => {
    let defer = $q.defer();
    $cordovaSocialSharing.shareViaTwitter(text, img, url)
        .then(defer.resolve, defer.reject);
    return defer.promise;
};
factory.playSound = (name) => $cordovaNativeAudio.play(name);
factory.alert = (title, text) => $ionicPopup.alert({
    title: title,
    template: text
});
return factory;
};

有人知道如何解决这个问题吗?我一直在寻找几天,无法弄清楚原因。谢谢!

修改

当我使用chrome://在虚拟设备中检查时(通过Genymotion),我在控制台中收到以下错误

  

TypeError:对象#没有方法'forEach'       在ChallengeCtrl.vm.onAfterEnter(文件:///android_asset/www/build/app.js:226:12)       at m。$ emit(file:///android_asset/www/lib/ionic/js/ionic.bundle.min.js:178:407)       at Object.q.emit(file:///android_asset/www/lib/ionic/js/ionic.bundle.min.js:470:20592)       at m(file:///android_asset/www/lib/ionic/js/ionic.bundle.min.js:470:19062)       在HTMLElement.g(文件:///android_asset/www/lib/ionic/js/ionic.bundle.min.js:470:18921)       在Pf(文件:///android_asset/www/lib/ionic/js/ionic.bundle.min.js:70:477)       在HTMLElement.Of.d(file:///android_asset/www/lib/ionic/js/ionic.bundle.min.js:70:424)ionic.bundle.min.js:150

onAfterEnter代码块可以在下面找到。

    vm.onAfterEnter = () => {
    //let ionViewDOM = $window.document.querySelectorAll('.challenge.pane .scroll-content')[0];
    let ionViewDOM = $window.innerHeight - 43;  // innerHeight minus the heigh of the title bar
    let popovers = $window.document.querySelectorAll('.message-popover');
    popovers.forEach((popover) => {
        //popover.style.height = `${ionViewDOM.clientHeight}px`;
        popover.style.height = ionViewDOM + `px`;
        if (ionViewDOM.clientHeight < 450) {
            popover.classList.add('small-screen');
        } else if (ionViewDOM.clientHeight < 550) {
            popover.classList.add('medium-screen');
        } else {
            popover.classList.remove('small-screen');
            popover.classList.remove('medium-screen');
        }
    });

    let params = NavigationService.getParams();
    ChallengeService.get(params.challenge)
        .then((result) => {
            vm.challenge = result;

            switch (vm.challenge.status) {
                case 'accepted':
                    vm.challengeAccepted = true;
                    break;
                case 'completed':
                    vm.challengeCompleted = true;
                    break;
            }
            NavigationService.setTitle(vm.challenge.gardenType.name);
            vm.challengeLoaded = true;

            ChallengeService.listRandomAvailableForUser(params.challenge, vm.challenge.gardenType.challenges)
                .then((result) => vm.randomChallenges = result);
        });
};

当我登录iPhone 5模拟器(通过XCode)时,我收到以下类似错误

  

错误:popovers.forEach不是函数。 (在'popovers.forEach'中,   'popovers.forEach'未定义)

所以它与弹出窗口有关。可能是$window.document.querySelectorAll('.message-popover')没有返回任何东西吗?具有message-popover类的div最初隐藏在页面上,仅在满足特定条件时显示(使用ng-show)。

1 个答案:

答案 0 :(得分:0)

在您遇到foreach错误的情况下,似乎您的页面未完全呈现。您是否尝试在页面上执行querySelectorAll之前设置超时或类似值?