1

I am using ionic + parse js sdk and would like to render only the true values from a checkbox.

Below is the scope:

$scope.Diagnosed = [
    { text: "Allergies", checked: true},
    { text: "ADHD", checked: false},
    { text: "Alcohol/Drug Dependence", checked: false},
    { text: "Asthma", checked: false},
    { text: "Autism", checked: false},
    { text: "Cancer", checked: false},
    { text: "Diabetes", checked: false},
    { text: "Eating Disorder", checked: false},
    { text: "Fertility Problems", checked: false},
    { text: "Heart Disease", checked: false},
    { text: "High Cholesterol", checked: false},
    { text: "Menopause", checked: false},
    { text: "Mood Disorders (e.g., anxiety, depression)", checked: false},
    { text: "Obesity", checked: false},
    { text: "Stroke", checked: false},
    { text: "Prefer not to answer", checked: false}

    ];

it looks like the following on the first page:

<ion-item  ng-class="" ng-repeat="object in lines" class="item-thumbnail-left item-icon-right item-text-wrap" href="#/moresurvey/{{object.id}}">

<a><h2>{{object.visafname}}</h2></a>
<h2 >{{object.visalname}}</h2>
<p>{{object.gender}}</p>
   <i class="icon ion-chevron-right icon-accessory"></i>

         <ion-option-button class="button" ng-click="deleteEvent(line)">
          Delete
        </ion-option-button>
      </ion-item>

And I am rendering the values on a different page using the below code:

query.get(id,{
success: function(response){

  var currentStart = 1
  for (var i = currentStart; i < response.length; i++) {
    var object = response[i];
          }

 $scope.Details = {
     diagnosed: response.get('diagnosed'),

  };
},
error: function(error){
   alert("Error: " + error.code + " " + error.message);
}
  });
};

And my html looks like the following:

</ion-item class="more-list">
  <ion-item class="item more-item">
    <i class="icon-left ion-cash more-icon"></i>
    <p class="moredetails location"> {{Details.diagnosed}}</p>
  </ion-item>
  </ion-item>
</ion-list>

On that page, the data is rendered like this:

 [{"checked":true,"text":"Allergies"},{"checked":false,"text":"ADHD"},{"checked":false,"text":"Alcohol/Drug Dependence"},{"checked":false,"text":"Asthma"},{"checked":false,"text":"Autism"},{"checked":false,"text":"Cancer"},{"checked":false,"text":"Diabetes"},{"checked":false,"text":"Eating Disorder"},{"checked":false,"text":"Fertility Problems"},{"checked":false,"text":"Heart Disease"},{"checked":false,"text":"High Cholesterol"},{"checked":false,"text":"Menopause"},{"checked":false,"text":"Mood Disorders (e.g., anxiety, depression)"},{"checked":false,"text":"Obesity"},{"checked":false,"text":"Stroke"},{"checked":false,"text":"Prefer not to answer"}]

But how do I only display the values that have been checked as true?

Thank you in advance..

1 Answer 1

0

Hi in your HTMl just check the condition for ng-if="item.checked" so if true only it will display

HTML

<ion-item ng-repeat="item in items" item="item" class="item-remove-animate">
<div class="p10" ng-if="item.checked">
    <ion-checkbox ng-model="item.checked"></ion-checkbox>
    <i class="icon-left ion-cash more-icon"></i>
    <p class="moredetails location"> {{item.text}}</p>
</div>

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for your response. Any idea how to do this when the data is being rendered on a different page? On the "moredetails" page I am not using ng-repeat to render results.
I've updated the post to reflect what I am talking about

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.