I have some nokia mobile models with some offers.Here two objects is there one for nokia models with price another one for offers.
For example i have offers for these two
1."brandname": "Nokia",
"model":"Lumia"
"submodel": "Lumia 735 TS"
2."brandname": "Nokia",
"model":"Lumia"
"submodel": "Lumia 830"
my expectation when ever checkbox is checked in that checkbox list.i need to check with offer object .if any offer is there for checked mobile model one dropdown should come and it will show that offer message.
for example:Lumia 735 TS is checked in that checkbox list .it has offer in that offer list so one drop down should come after that checkbox list it should show "Offer_message":"1000rs off" offer message .if i unchecked that dropdown should not show.demo
here Lumia 735 TS", "Lumia 510 both checked in my demo so it should show two offer message in that drop down list
var myApp = angular.module('myApp',[]);
//myApp.directive('myDirective', function() {});
//myApp.factory('myService', function() {});
myApp.controller("MyCtrl", MyCtrlFun);
function MyCtrlFun($scope) {
//****** Selected List****
$scope.selectedlist = ["Lumia 735 TS", "Lumia 510"];
$scope.checkbox_model = [];
$scope.checkbox_list = [];
$scope.checkItems = function(){
$scope.checkbox_list = [];
for(var item in $scope.checkbox_model){
if($scope.checkbox_model[item].isChecked)
{
$scope.checkbox_list.push($scope.checkbox_model[item]);
}
}
alert(JSON.stringify($scope.checkbox_list));
}
$scope.selectedbrand = 'Nokia';
$scope.submodel ='Lumia';
$scope.phones = [{
"_id": {
"$oid": "56a9c44f40d0275643cfc04e"
},
"default": [],
"Categories": [
{
"models": [
{
"submodel": [
{
"price": "7500",
"name": "Lumia 735 TS"
},
{
"price": "8100",
"name": "Lumia 510"
},
{
"price": "9900",
"name": "Lumia 830"
}
],
"name": "Lumia"
},
{
"submodel": [
{
"price": "10000",
"name": "Asha 230"
},
{
"price": "11999",
"name": "Asha Asn01"
}
],
"name": "Asha"
}
],
"brandname": "Nokia",
"id": "986745"
},
{
"models": [
{
"submodel": [
{
"price": "5000",
"name": "Trend 840"
},
{
"price": "6999",
"name": "A5"
}
],
"name": "Galaxy"
},
{
"submodel": [
{
"price": "12000",
"name": "Asha 230"
}
],
"name": "Asha"
}
],
"brandname": "Samsung",
"id": "144745"
}
],
"Storename": "Zig Zag Mobiles",
"Shopid":"asdef1234",
"__v": 0
}
]
//----------------------------Our Shop Offers----------------------------------------
$scope.offers = [
{
id: "as23456",
"Storename": "Zig Zag Mobiles",
"Shopid":"asdef1234",
"Offer_message":"1000rs off",
"Categories": [
{
"models": [
{
"submodel": [
{
"price": "1000",
"name": "Lumia 735 TS"
}
],
"name": "Lumia"
}
],
"brandname": "Nokia",
"id": "986745"
}
],
},{
id: "de34575",
"Storename": "Zig Zag Mobiles",
"Shopid":"asdef1234",
"Offer_message":"500rs off",
"Categories": [
{
"models": [
{
"submodel": [
{
"price": "500",
"name": "Lumia 830"
}
],
"name": "Lumia"
}
],
"brandname": "Nokia",
"id": "345645"
}
],
},
{
id: "ert25675",
"Storename": "Zig Zag Mobiles",
"Shopid":"asdef1234",
"Offer_message":"100 Flat",
"Categories": [
{
"models": [
{
"submodel": [
{
"price": "100",
"name": "Asha 230"
}
],
"name": "Asha"
}
],
"brandname": "Samsung",
"id": "345645"
}
],
}
]
//-----------------------------------------------------------------------------------
for(var i=0; i<$scope.phones.length; i++){
for(var j=0; j<$scope.phones[i].Categories.length; j++){
if($scope.phones[i].Categories[j].brandname==$scope.selectedbrand){
for(var k=0; k<$scope.phones[i].Categories[j].models.length; k++){
if($scope.phones[i].Categories[j].models[k].name==$scope.submodel){
for(var m=0; m<$scope.phones[i].Categories[j].models[k].submodel.length; m++){
var verifyIsCheck = false;
if($scope.selectedlist.length>0){
verifyIsCheck=verifyIsChecked($scope.phones[i].Categories[j].models[k].submodel[m].name);
}
$scope.checkbox_model.push({isChecked :verifyIsCheck, name : $scope.phones[i].Categories[j].models[k].submodel[m].name, price:$scope.phones[i].Categories[j].models[k].submodel[m].price});
}
}
}
}
}
}
function verifyIsChecked(submodel_name){
for(var i=0; i<$scope.selectedlist.length; i++){
if($scope.selectedlist[i]==submodel_name){
return true;
}
}
return false;
}
}
//]]>
//]]>
<div ng-app="myApp" ng-controller="MyCtrl">
<div class="item" ng-repeat="item in phones">
<div ng-repeat="cat in item.Categories" ng-show="cat.brandname==selectedbrand">
<h2><b>{{ cat.brandname }}</b></h2>
<div ng-repeat="models in cat.models" ng-show="models.name==submodel">
<h3>
<b>{{models.name}}</b>
</h3>
<div ng-repeat="submodels in models.submodel">
<input type="checkbox" ng-model="checkbox_model[$index].isChecked"/>{{ submodels.name }}
</div>
</div>
</div>
<button ng-click="checkItems()">Do</button>
</div>
</div>
Aucun commentaire:
Enregistrer un commentaire