ฟังก์ชันค้นข้อมูลจาก DB ตามเงื่อนไข โดยใช้ IONIC

แลกเปลี่ยนประสบการณ์และ ปัญหาการใช้งาน Mobile การพัฒนา App บน SmartMobile , tablet Android, iOS, Window Phone และ ฯลฯ

Moderator: mindphp, ผู้ดูแลกระดาน

tanawit

ฟังก์ชันค้นข้อมูลจาก DB ตามเงื่อนไข โดยใช้ IONIC

โพสต์ที่ยังไม่ได้อ่าน โดย tanawit »

ตอนนี้ผมกำลังหัดสร้างแอปโดยใช้ Ionic framework ครับ แล้วกำลังติดปัญหาตรงที่ฟังก์ชันการค้นหาข้อมูลให้แสดงออกมาให้ตรงตามเงื่อนไขอะครับ ซึ่งตอนนี้โค้ดให้ฟอร์มส่งข้อมูลไปยัง php ได้แล้ว แต่ไม่สามารถทำให้ข้อมูลมาแสดงได้

อันนี้เป็นโค้ดฝั่ง html ที่ให้ระบุเงื่อนไข

โค้ด: เลือกทั้งหมด

<ion-view view-title="เลือกยี่ห้อ">
  <ion-content class="padding">

    <form ng-submit="viewGarage()" ng-controller="DataCtrl">
      <ul class="list">

        <li class="list">
          <label class = "item item-input item-select" >
            <div class = "input-label">
              เลือกยี่ห้อรถ
            </div>
            <select ng-model="garageData.brand">
              
              <option ng-repeat="b in showBrands" value="{{b.id_b}}">{{b.name_b}}</option>
            </select>
            <!--<input type="text" ng-model="garageData.brand">-->

          </label>
        </li>

        <li class="list">
          <button class="button button-block button-positive" type="submit" >ค้นหา</button>
        </li>

      </ul>
    </form>

  </ion-content>
</ion-view>
ส่วนถัดไปเป็นส่วน js ครับ

โค้ด: เลือกทั้งหมด

angular.module('starter.controlManageData', [])
  .controller('DataCtrl', function($scope, $ionicModal, $timeout, $ionicPopup, $http, $state, $ionicHistory, $stateParams) {
    //path connect file php
    var url='...'; 
    
    $http.get(url+"brand-show.php").success(function(response){
      $scope.showBrands=response.records;

    }).error(function () {

      $ionicPopup.alert({
        title:'ข้อมูลอู่ซ่อมรถ',
        template:'ไม่สามารถทำการติดต่อเซิร์ฟเวอร์ได้'
      });
    });

   
    $scope.garageData={};
    $scope.viewGarage = function(){

      var brand = $scope.garageData.brand;
      //alert(brand);

      if(brand){
        $http.get(url+"detailGarage-show.php?brand="+brand).success(function(response){

          $scope.showDetail=response.records;
          $state.go('app.detailGarage',[],{location:"replace",reload:true});

        }).error(function () {

          $ionicPopup.alert({
            title:'ข้อมูลอู่ซ่อมรถ',
            template:'ไม่สามารถทำการติดต่อเซิร์ฟเวอร์ได้'
          });
        });

        
      }
    };


    /*end contrller*/
  })
และก็ส่วนนี้เป็นส่วนที่ต้องการให้ข้อมูลออกมาแสดงครับ ซึ่งจะแสดงให้ตรงตามเงื่อนไขที่ระบุไป

โค้ด: เลือกทั้งหมด

<ion-view view-title="ข้อมูลอู่ซ่อมรถ">
  <ion-content class="padding">
    <div class="card" ng-controller="DataCtrl" ng-repeat="detail in showDetail">

      <input type="hidden" ng-model="garageData.brand">

      <div class="item item-text-wrap">
        <div class = "input-label">
          ชื่อ : {{detail.name_garage}}
        </div>
        <div class = "input-label">
          ยี่ห้อ : {{detail.brand}}
        </div>

      </div>
    </div>

  </ion-content>
</ion-view>
ไม่รู้ว่าผมจะอธิบายเข้าใจหรือป่าวนะครับ ยังไงก็ขอรบกวนด้วยนะครับ (มือใหม่หัดโค้ดครับ :-D )
  • Similar Topics
    ตอบกลับ
    แสดง
    โพสต์ล่าสุด

ผู้ใช้งานขณะนี้

สมาชิกกำลังดูบอร์ดนี้: ไม่มีสมาชิกใหม่ และบุคลทั่วไป 70