【发布时间】:2015-08-09 10:24:03
【问题描述】:
<div ng-controller="SamsungServicesCtrl">
<ion-content>
<li class="item item-checkbox" ng-repeat="item in items" >
<img src="{{item.icon}}" style="float:left;height:30px;width:30px;padding-right:5px;" >
<label class="checkbox checkbox-energized" >
<input type="checkbox" style="float:right;" ng-model="item.selected" >
</label>
{{item.name}}
<p style="font-size:10px; padding-left:0px;"> {{item.subname}}</p>
</li>
<div class="padding">
<button class="button button-full button-energized" value="submit" ng-click="check()">Apply
</button>
</div>
</ion-content>
</div>
<script>
.controller('SamsungServicesCtrl', function ($scope,$filter,$location) {
var service = ["Regular Service", "Settings Faults", "Software Faults", "Hardware Faults"];
var services = ["General services", "If a phone doesn’t switch-on, it is called a dead phone, SIM card does not get detected", "Hardware Faults"];
var icons = ["images/arrow.svg","images/arrow.svg","images/arrow.svg"];
$scope.items= [] ;
for(var I=0;I<service.length;I++)
{
var modal = {
name:service[I],
subname:services[I],
icon:icons[I],
selected:false
};
$scope.items.push(modal);
}
scope.check = function()
{
var checkedItems = [];
for(var I=0;I<$scope.items.length;I++){
if($scope.items[I].selected){
checkedItems.push($scope.items[I].name);
}
}
//I have checked Regular Service, Settings Faults
$location.path('listing').search({model: 'samsung', items:checkedItems});
}
})
</script>
我已经给了我的服务页面 html 和控制器。在此页面中包含服务列表,这是我的第一页,用户需要选择其中任何一项服务。用户单击应用按钮后,我将重定向到包含所选服务的列表页面:商店类型(诺基亚,三星)($location.path('listing').search({model:'samsung',items:checkedItems}))。这里用户只选择了服务,但我将型号名称附加为三星。
<div class="bar bar-header item-input-inset">
<label class="item-input-wrapper" >
<I class="icon ion-ios-search placeholder-icon"></I>
<input type="text" placeholder="Search" ng-model="query" >
</label>
</div>
<div class="list card" data-ng-repeat="dealer in dealers | filter:query ">
<div class="item item-thumbnail-left item-icon-right" href="#">
<h2>{{dealer.Store_Name}}</h2>
<p>{{dealer.S_Address.area}} {{dealer.S_Address.city}}</p>
<p>{{dealer.S_Services}}</p>
</div>
</div>
listing page
<script>
listing controller
.controller('ListingCtrl', [
'$scope', '$http', '$location', '$window', '$filter','$ionicPopover','$ionicLoading',
function($scope, $http, $location, $window, $filter, $ionicPopover, $ionicLoading) {
$scope.dealers = [{
S_Date_add: "2015-07-24T13:45:23.927Z",
S_Email_id: "aditiya@gmail.com",
S_Store: "samsung",
Store_Name: "Adtiya Samsung Store",
S_Services: "Regular Service,Software Faults,Hardware Faults,Interior faults",
Store_long_description: "Undertake all kind of samsung mobiles",
Store_short_description: "Undertake all kind of samsung mobiles",
}, {
S_Date_add: "2015-07-24T13:45:23.927Z",
S_Email_id: "rajs@gmail.com",
S_Store: "nokia",
Store_Name: "sri shakthi mobile service",
S_Services: "Settings Faults,Regular Service,Hardware Faults",
Store_long_description: "Undertake all kind of nokia mobiles",
Store_short_description: "Undertake all kind of nokia mobiles",
}, {
S_Date_add: "2015-07-24T13:45:23.927Z",
S_Email_id: "sprtive23@gmail.com",
S_Store: "nokia,samsung",
Store_Name: "sun mobile service center",
S_Services: "overall faults,Regular Service,",
Store_long_description: "Undertake all kind of nokia,samsung mobiles",
Store_short_description: "Undertake all kind of nokia,samsung mobiles"
}, {
S_Date_add: "2015-07-24T13:45:23.927Z",
S_Email_id: "siva@gmail.com",
S_Store: "nokia,samsung",
Store_Name: "mobile service center",
S_Services: "overall faults,mobile faults",
Store_long_description: "Undertake all kind of nokia,samsung mobiles",
Store_short_description: "Undertake all kind of nokia,samsung mobiles"}
]
var model = $location.search().model;
var items = $location.search().items;
console.log(filter);
//filter value iam getting in console samsung
console.log(items);
//items value getting in console Regular Service,Hardware Faults
//I have done some logic here to check
$scope.dealers=[];
for(var I=0;I<data.length;I++){
var temp=data[I].S_Store.split(',');
var temp1=data[I].S_Services.split(',');
for(var j=0;j<temp.length:j++){
for(var k=0;j<temp1.length:k++)
{
if(temp[j]===model ||temp1 === items)
$scope.dealers.push(data[I]);
}
}
}
}])
</script>
上面的代码列表页面 html 和控制器。在此页面中,我需要根据用户选择显示商店。在列表页面中,我正在获取模型值和项目值。
店铺列表应为:
- 模型应与 S_Store 匹配
-
项目应与 S_Services 匹配
我做了逻辑,但它不起作用
示例条件 如果用户来自三星页面,那么我将模型值附加为三星 并且用户选择了常规服务,硬件故障。在这里我像这样重定向 $location.path('listing').search({model: 'samsung', items:'常规服务,硬件故障'}); 所以我在控制台中检查了选定的值,它即将到来 但我需要显示匹配的商店列表 1. Adtiya三星商店 2. sri shakthi 移动服务 3.太阳移动服务中心
【问题讨论】:
标签: javascript jquery angularjs