I'm encountering a problem and I will appreciate someone can help.
Right now I'm showing several checkboxes in my form which are grabbing from my firebase database. And in my controller I'm trying to use ng-submit to store whole data of form. My checkbox JSON format should look like this.
{
"apple" : true,
"spotify" : true
}
okay the following is my code from HTML and Javascript
<label class="checkbox-inline" ng-repeat="hashtag in hashtags" for="{{hashtag}}">
<input type="checkbox" name="{{hashtag.$value}}" id="{{hashtag.$value}}" value="{{hashtag.$value}}" ng-model="hashtag.SELECTED" ng-true-value="true" ng-false-value="false">
{{hashtag.$value | capitalize}}
</label>
My Javascript here
form.$add({
description: $scope.inputDescription,
hashtags: {
*I don't know how to put checkbox's result here.*
},
time: Firebase.ServerValue.TIMESTAMP,
title: $scope.inputTitle,
url: $scope.inputUrl
})
Anyone can help, please? Thank you so much.
Update Thanks for the reply. I really appreciate those! However, I found out that I forgot to mention something and I tried the answers from the reply and they didn't work. The picture below will explain my problem. enter image description here Thank you so much!
Finally solution in case people are curious about the answer I just figured out. The following is my solution. Thank you guys! I love stackoverflow!
function checkbox(hashtags) {
var arr = {};
for(var hashtag in hashtags) {
if(hashtags[hashtag].SELECTED === true){
arr[hashtags[hashtag].$value] = true;
}
}
return arr;
}
hashtagsthe first described JSON?