我可以通过instanceId获得唯一的ID,但是在开发人员控制台的代码块中却遇到了这样的错误。
Expected:
<div id="deneme-carousel-1" class="owl-carousel owl-theme"></div><script>jQuery( document ).ready( function() { jQuery('#deneme-carousel-1').owlCarousel();</script>
Actual:
<div id="deneme-carousel-21" class="owl-carousel owl-theme"></div><script>jQuery( document ).ready( function() { jQuery('#deneme-carousel-21').owlCarousel();</script>
index.js
save: withInstanceId( function( { instanceId} ) {
return(
<div id={`deneme-carousel-${ instanceId }`} className={ classnames( 'owl-carousel', 'owl-theme', className ) }>
</div>
<script>
{'function() { jQuery(\'#'+`deneme-carousel-${instanceId}`+'\').owlCarousel();'}
</script>
} ),