如何在html

时间:2016-01-12 07:27:38

标签: angularjs cordova ionic

在我的主页上,我添加了一个名为“城市”的按钮。单击它会打开一个列出城市名称的弹出窗口。点击城市'paris'时,必须显示带有城市名称的数据。

主页

 <ion-header-bar class="bar bar-subheader">   
            <button class="button button-flat button-positive"ng-click="citypopup();" style="padding-right: 63px;
    padding-left: 18px;"> 
                <l >City </l>
                <l class="icon ion-chevron-down"></l>
            </button>

    </ion-header-bar> 

    <ion-content> 
          <div class='card ' ng-repeat="item in list  | filter:test.searchCity ">
                 <div class="list "  >
                    <div class='item' style="padding-top:0px;" >  {{item.id}}
                        <l class="item-icon-right" style="padding-left:30%"> {{item.date}} </l>
                    </div>

                    <div class='item' style="padding-top:0px;" >{{item.status }}
                        <l class="item-icon-right" style="text-align:right;">{{item.QCstatus}}</l>
                        <i class="icon ion-chevron-right"></i>
                    </div>
                    <b class='item '> {{item.Factory}} </b>
                    <l class='item '>{{item.city }}</l>
                </div>

弹出页面

<ion-list> 
    <ul class="list" ng-model="test.searchCity" ng-repeat="ci in cityList | orderBy:'city' " >
        <li class="item" ng-click="test.searchCity">{{ci.city}}  </li>      
    </ul>
</ion-list>

的javascript

$scope.test = {
    searchCity: null,       
};

$scope.cityList = [
    {
        "city": "Chennai"
    }, {
        "city": "Banglore"
    }, {
        "city": "Delhi"
    }
];

$scope.list = [
    {  
        id: "#001",
        date:"DEC 04 2016",
        status: "Successful",
        QCstatus: "Approve",
        Factory: "ARUN ICE CREAM",
        city: "paris"
    },
    {
        id: "#002",
        date: "JAN 11 2016",
        status: "Successful",
        QCstatus: "Approve",
        Factory: "Floxtronics",
        city: "Delhi"
    },
    {
        id: "#003",
        date: "Feb 14 2016",
        status: "Bug fixing",
        QCstatus: "Approve",
        Factory: "Aachi",
        city: "Chennai"
    }           
];

$scope.$watch('test.searchCity', function () {
    $scope.test.searchCity = null;
    console.log('test.searchCity')
});

$scope.citypopup = function() {
    var myPopup = $ionicPopup.show({
        scope: $scope,
        templateUrl: 'templates/cityTemplate.html',    
        buttons: [
            { text: 'Cancel',
             type: 'button-positive' },            
        ]
    });

}

我需要的是当我点击“城市”按钮时,我的城市弹出窗口出现,当我点击城市时没有任何反应!有人能帮助我吗?

2 个答案:

答案 0 :(得分:0)

您永远不会分配test.searchCity

在您的弹出页面代码中使用ng-click="test.searchCity",您可能应该使用ng-click="test.searchCity = ci.city"

与您的问题无关(但正确使用模式):ngModel元素中不需要ul(仅适用于表单元素),{{1在ng-repeat s而不是li s上使用时更有意义。

总结:

ul

答案 1 :(得分:0)

无需创建另一个弹出页面,您可以在 citypopup() 功能

中打开弹出内容
$scope.citypopup = function() {
  $scope.popup = $ionicPopup.show({         
      template:"<ion-list><ul class='list' ng-model='test.searchCity' ng-repeat='ci in cityList | orderBy:city ' ><li class='item' ng-click='searchCity(ci.city)'>{{ci.city}}  </li> </ul></ion-list>" ,
      title: 'City',
      scope: $scope        
  });
}

$scope.searchCity = function(city){
   $scope.test.searchCity = city;    
   $scope.popup.close();
}