当网址更改时,离子侧菜单显示相同的内容

时间:2015-02-26 15:07:53

标签: javascript angularjs ionic-framework deferred

我从我的数据库中获取一些数据并将其显示在视图上,我遇到的问题是,当我点击sidemenu转到另一个页面时,它会一直显示相同的内容。路线是正确的我已经检查过,他们正在使用各自的控制器。我不知道我在这里失踪了什么。任何帮助将不胜感激。

 var showClientes = function findAllClientes() {
            db.transaction(
                function(tx) {
                    var sql = "SELECT *FROM clientes";
                    tx.executeSql(sql, [],
                        function(tx, results) {
                            var len = results.rows.length,
                                clientes = [],
                                i = 0;
                            for (; i < len; i = i + 1) {
                                clientes[i] = results.rows.item(i);
                            }
                            log(i + ' clientes  found');
                            deferred.resolve(clientes);

                        }
                    );
                },txErrorHandler,
                function () { }
            );
            return deferred.promise;

        };

        var showPedidos = function findAllPedidos() {
            db.transaction(
                function(tx) {
                    var sql = "SELECT * FROM pedidos";
                    tx.executeSql(sql, [],
                        function(tx, results) {
                            var len = results.rows.length,
                                pedidos = [],
                                i = 0;
                            for (; i < len; i = i + 1) {
                                pedidos[i] = results.rows.item(i).numero;
                            }
                            log(i + ' pedidos  found');
                            deferred.resolve(pedidos);

                        }
                    );
                },txErrorHandler,
                function () { }
            );
            return deferred.promise;

        };



        return {
            showClientes: showClientes,
            showPedidos: showPedidos
        };

控制器:

.controller('PedidosCtrl', function ($scope, dbFactory) {

        dbFactory.showPedidos(function(listpedidos) {
            $scope.pedidos = listpedidos;
            console.log($scope.pedidos);
        });

    })

    .controller('ClientesCtrl', function ($scope, dbFactory) {

        dbFactory.showClientes().then(function(listview) {
            $scope.clientes = listview;
            console.log($scope.clientes);
        });

    });

菜单:

<ion-side-menus enable-menu-with-back-views="false">
  <ion-side-menu-content>
    <ion-nav-bar class="bar-stable">
      <ion-nav-back-button>
      </ion-nav-back-button>

      <ion-nav-buttons side="left">
        <button class="button button-icon button-clear ion-navicon" menu-toggle="left">
        </button>
      </ion-nav-buttons>
    </ion-nav-bar>
    <ion-nav-view name="menuContent"></ion-nav-view>
  </ion-side-menu-content>

  <ion-side-menu side="left">
    <ion-header-bar class="bar-stable">
      <h1 class="title">Left</h1>
    </ion-header-bar>
    <ion-content>
      <ion-list>
        <ion-item nav-clear menu-close ng-click="login()">
          Login
        </ion-item>
        <ion-item nav-clear menu-close href="#/app/viagens">
          Viagens
        </ion-item>
        <ion-item nav-clear menu-close href="#/app/pedidos">
          Pedidos
        </ion-item>
        <ion-item nav-clear menu-close href="#/app/clientes">
          Clientes
        </ion-item>
      </ion-list>
    </ion-content>
  </ion-side-menu>
</ion-side-menus>

clientes.html:

<ion-view view-title="Clientes">
    <ion-content>
        <ion-list>
            <ion-item ng-repeat="cliente in clientes">
                {{cliente.nome}}
            </ion-item>
        </ion-list>
    </ion-content>
</ion-view>

pedidos.html:

<ion-view view-title="Pedidos">
    <ion-content>
        <ion-list>
            <ion-item ng-repeat="pedido in pedidos">

            {{pedido.numero_pedido}}
            {{pedido.data_emissao}}

            </ion-item>
        </ion-list>
    </ion-content>
</ion-view>

0 个答案:

没有答案