【问题标题】:ionic : how to filter data in a select element based on a another one离子:如何根据另一个元素过滤选择元素中的数据
【发布时间】:2015-11-03 14:06:57
【问题描述】:

我的数据库中有 2 个表,名为:transporteur 和 camion,每个 transporteur 都有许多 camions:

CREATE TABLE IF NOT EXISTS `camion` (
`id` int(11) NOT NULL,
  `matricule` varchar(255) NOT NULL,
  `idTransporteur` int(11) NOT NULL
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=latin1;  

CREATE TABLE IF NOT EXISTS `transporteur` (
`id` int(11) NOT NULL,
  `codeTransporteur` varchar(255) NOT NULL,
  `RS` varchar(255) NOT NULL
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1;

ALTER TABLE `camion`
 ADD PRIMARY KEY (`id`), ADD KEY `FK_1` (`idTransporteur`);

HTML:

<label class="item item-input item-select">
    <div class="input-label">transporteur</div>
    <select ng-model="transp">
        <option ng-repeat="x in transporteur">{{x[1]}}</option>
    </select>
</label> 


<label class="item item-input item-select">
    <div class="input-label">matricule camion</div>
    <select ng-model="matriculeCamion" >
        <option ng-repeat="x in camion">{{x[1]}}</option>
    </select>
</label>

控制器:

.controller('AddController',['$scope','$http','$state',function($scope,$http,$state){

  var request = $http({
    method: "post",
    url: "http://localhost:8180/ExtractDataSelect.php",
    headers: { 'Content-Type': undefined }
  });

  request.success(function(data,status,headers,config) {
    $scope.camion=data.camion;
    $scope.transporteur=data.transporteur;   
  });

}])

我想根据选择的codeTransporteur显示camion数据。

【问题讨论】:

  • 你能告诉我$scope.camion$scope.transporteur的示例输出吗?
  • 应用程序的输出??! @mhx
  • 是的,请求在其成功函数中返回什么? (data.camion & data.transporteur)
  • 它返回所有数据(camions 和 transporteurs).. 从 db @mhx 选择所有数据时没有错误

标签: angularjs select filter ionic-framework ionic


【解决方案1】:

我终于找到了解决方案。我应该在我的选择元素中添加一个ng-if,:

<label class="item item-input item-select">
            <div class="input-label">transporteur  </div>
            <select ng-model="transp" >
              <option ng-repeat="x in transporteur ">{{x[1]}}</option>
            </select>
          </label> 


           <label class="item item-input item-select">
            <div class="input-label">matricule camion  </div>
            <select ng-model="matriculeCamion" >
              <option ng-repeat="x in camion" ng-if=" x[3] == transp">{{x[1]}}</option>
            </select>
          </label>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-10-14
    • 2018-07-14
    • 2021-10-13
    • 2017-08-06
    • 2020-07-15
    相关资源
    最近更新 更多