All the provided examples are using id as selector and passed 'initialRating' in the initializing function. But in my case I have a loop of start rating available objects. Looping entire initialization is not ideal. So I have used class to initialize and it works. But now the 'initialRating' is hard coded. I have current rating of each my item in 'data-current-rating' attribute. How to get this value in the initialization ?
Here is my code :
$('.shop-rating').barrating({
theme: 'fontawesome-stars-o',
showSelectedRating: false,
initialRating: '3', //I want to get this from 'data-current-rating'.
onSelect: function(value, text, event) {
var el = this;
var shop_id = el.$elem.data('shop-id');
if (!value) {
/*$('#example-fontawesome-o')
.barrating('clear');*/
} else {
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
$.ajax({
type: "POST",
url: '{!! route('doRating') !!}',
data: {'shop_id':shop_id, 'rating' : value},
success: function(response) {
console.log(response);
}
},'json');
}
}
});
All the provided examples are using id as selector and passed 'initialRating' in the initializing function. But in my case I have a loop of start rating available objects. Looping entire initialization is not ideal. So I have used class to initialize and it works. But now the 'initialRating' is hard coded. I have current rating of each my item in 'data-current-rating' attribute. How to get this value in the initialization ?
Here is my code :