如何从angularjs

时间:2015-10-07 11:11:02

标签: javascript angularjs web-services radio-button

我是angularjs的新手,我做了一个演示,其中有一个radiobutton列表。他们有与它们相关的值,(数据来自json形式的webservice)现在我想得到与之相关的价值单击列表中的特定复选框,我也得到了一个演示,但仍然没有运气,anybuddy请帮助我吗? 的 JS

   app.controller('filterController',  function ($http, $scope, $compile, $filter, $sce)
 {

    var page = gallery.getCurrentPage();
   var Catid = page.options.params;

       var Content ='';
       var areacontent = '';
       var cusinecontent = '';
       var catcontent = '';


       //headers..

       var hdrcuine = '<ons-list-header>'+
          '<ons-row>'+
            '<ons-col>Cuisine'+'</ons-col>'+
            '<ons-col width="35px" style="flex: 0 0 35px; max-width: 35px;">'+
                '<ons-icon icon="ion-android-add-circle" fixed-width="true">'+'</ons-icon>'+
            '</ons-col>'+
          '</ons-row>'+
        '</ons-list-header>';

    var hdrarea =  '<ons-list-header>'+
          '<ons-row>'+
            '<ons-col>Area'+'</ons-col>'+
            '<ons-col width="35px" style="flex: 0 0 35px; max-width: 35px;">'+
                '<ons-icon icon="ion-android-add-circle" fixed-width="true">'+'</ons-icon>'+
            '</ons-col>'+
          '</ons-row>'+
        '</ons-list-header>'; 

var hdrcat =  '<ons-list-header>Categories'+
                '</ons-list-header>'; 

    $scope.areaval = '';
//     $scope.list = {
//        name: '1',
//        intglcode:'0'
//      };
//      
//      $scope.rate={
//          rate:'1',
//          intglcode:'0'
//          
//      };
//      
//      $scope.area={
//          area:'Camana bay',
//          intglcode:'0'
//      };
//      
//      $scope.cusine={
//          cusine:'Pizza',
//          intglcode:'0'
//      };
//      $scope.cat={
//          cat:'Restaurant',
//          intglcode:'0'
//      };
//   

        $http({
            method: 'POST',
            url:  API_HOST+'/webservice/Get_FilterDetails',
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded',
                'caymanauth': caymanauth
            },
              data: '&Catid='+Catid

        }).success(function (data) 
            {  


                 for(var i=0; i < data.Details.length; i++){

            //PARSING DATA FOR RATYE TYPES.
            if(data.Details[i] === "Rate Type"){

                for(var d=0;d<5;d++)
                {            


                         $scope.list.intglcode = data.Details[i+1][d]['intGlCode'];



                     console.log("===========my rate types==========="+data.Details[i+1][d]['intGlCode']);

                }    
                   gRate = data.Details[i+1][d]['intGlCode'];

   }
            //PARSING DATA FOR LISTING TYPES.
               if(data.Details[i] === "Listing Type"){
                     for(var d=0;d<5;d++){
                     console.log("===========my Listing types==========="+data.Details[i+1][d]['intGlCode']);
                }

   }
            //PARING FOR AREA
            if(data.Details[i] === "Area"){
                     for(var d=0;d<17;d++){

                         if(areacontent === ''){
                            var val =data.Details[i+1][d]['intGlCode'];
                             areacontent = '<ons-list-item modifier="tappable">'+
          '<label class="checkbox checkbox--list-item">'+
              '<input type="radio" ng-model="areaval" name="area" value={{val}}>'+
            '<div class="checkbox__checkmark checkbox--list-item__checkmark">'+'</div>'+data.Details[i+1][d]['varCityName']+    
          '</label>'+
        '</ons-list-item>';
                         }else{
                               areacontent += '<ons-list-item modifier="tappable">'+
          '<label class="checkbox checkbox--list-item">'+
              '<input type="radio" ng-model="areaval" name="area" value={{val}}>'+
            '<div class="checkbox__checkmark checkbox--list-item__checkmark">'+'</div>'+data.Details[i+1][d]['varCityName']+    
          '</label>'+
        '</ons-list-item>';
                         }
                     console.log("===========my Area types==========="+data.Details[i+1][d]['intGlCode']);
                }

   } 
   //PARSING DATA FRO CUSINE
     if(data.Details[i] === "Cuisine"){
                   for(var d=0;d<7;d++){

                       if(cusinecontent === ''){
                             cusinecontent = '<ons-list-item modifier="tappable">'+
          '<label class="checkbox checkbox--list-item">'+
          '<input type="radio" ng-model="cusine.name" name="cusine" value="Asian">'+
            '<div class="checkbox__checkmark checkbox--list-item__checkmark">'+'</div>'+data.Details[i+1][d]['varName']+
          '</label>'+
        '</ons-list-item> ';
                       }else{
                              cusinecontent += '<ons-list-item modifier="tappable">'+
          '<label class="checkbox checkbox--list-item">'+
          '<input type="radio" ng-model="cusine.name" name="cusine" value="Asian">'+
            '<div class="checkbox__checkmark checkbox--list-item__checkmark">'+'</div>'+data.Details[i+1][d]['varName']+
          '</label>'+
        '</ons-list-item> ';
                       }
                     console.log("===========my cusine types==========="+data.Details[i+1][d]['intGlCode']);
                }

   } 

   //PARSING DATA FOR CATEGORIES
    if(data.Details[i] === "Categories"){
                    for(var d=0;d<14;d++){
                         if(catcontent  === ''){
                             catcontent = '<ons-list-item modifier="tappable">'+
          '<label class="checkbox checkbox--list-item">'+
             +" "+'<input type="radio" ng-model="cat.name" name="cat" >'+
            '<div class="checkbox__checkmark checkbox--list-item__checkmark">'+'</div>'+data.Details[i+1][d]['varName']+
            '</label>'+
        '</ons-list-item>';
                         }else{
                                catcontent += '<ons-list-item modifier="tappable">'+
          '<label class="checkbox checkbox--list-item">'+
             '<input type="radio" ng-model="cat.name" name="cat" >'+
            '<div class="checkbox__checkmark checkbox--list-item__checkmark">'+'</div>'+data.Details[i+1][d]['varName']+
            '</label>'+
        '</ons-list-item>';
                         }
                     console.log("===========my category types==========="+data.Details[i+1][d]['intGlCode']);
                }
   } 
   //return data.Details[i + 1];

}   
Content = hdrarea+areacontent+hdrcuine+cusinecontent+hdrcat+ catcontent;
 $scope.snippet = Content;
            $scope.deliberatelyTrustDangerousSnippet = function ()
            {
                return $sce.trustAsHtml($scope.snippet);
            };


        }).error(function () {
            alert("error");
        });

 $scope.submitForm = function () {
       alert($scope.areaval);
   };

1 个答案:

答案 0 :(得分:0)

我在控制器内使用$watch指令得到了我的解决方案,它将返回$ scope variable的更改值。谢谢4 suport