Blade和JavaScript - 如何从属性中的字符串中删除空格

时间:2022-03-05 19:20:22

So I have a title attribute inside my elements because I want to use Bootstrap's tooltip. However I may have different options depending on the data. I am doing a @foreach loop between the quotes of the title attribute. However if there is more than one thing to be printed the tooltip box gets broken and I get this enormous whitespace. I think a possible solution/workaroud would be to use JS or JQuery to trim the whitespaces. How can I do that? here is my code and how the tooltip looks like if there are more than one iterations.

所以我的元素中有一个title属性,因为我想使用Bootstrap的工具提示。但是,根据数据的不同,我可能有不同的选择。我正在title属性的引号之间进行@foreach循环。但是,如果要打印多个东西,工具提示框会被破坏,我会得到这个巨大的空白。我认为一个可能的解决方案/ workaroud将使用JS或JQuery来修剪空白。我怎样才能做到这一点?这是我的代码以及如果有多个迭代,工具提示的样子。

<option data-toggle="tooltip" title="
@foreach($availableOption->optionIncompatibilities as $optionIncompatibility)
     Not available when:  {{ $optionIncompatibility->disabled_by_id1 }}
@endforeach
">

Blade和JavaScript  - 如何从属性中的字符串中删除空格

Other solutions and advice would be really helpful. Thanks in advance!

其他解决方案和建议将非常有用。提前致谢!

1 个解决方案

#1


2  

Try this:

<?php 

$tooltip = '';

?>
@foreach($availableOption->optionIncompatibilities as $optionIncompatibility)
    <?php
    $tooltip .=  'Not available when:' . $optionIncompatibility->disabled_by_id1;
    ?>
@endforeach

<option data-toggle="tooltip" title="{{ $tooltip }}">

Make the loop and create the tooltip value first before using it.

在使用之前,首先创建循环并创建工具提示值。

Note: I hope this will help you, though I haven't tested it.

注意:我希望这对你有所帮助,尽管我还没有测试过。

#1


2  

Try this:

<?php 

$tooltip = '';

?>
@foreach($availableOption->optionIncompatibilities as $optionIncompatibility)
    <?php
    $tooltip .=  'Not available when:' . $optionIncompatibility->disabled_by_id1;
    ?>
@endforeach

<option data-toggle="tooltip" title="{{ $tooltip }}">

Make the loop and create the tooltip value first before using it.

在使用之前,首先创建循环并创建工具提示值。

Note: I hope this will help you, though I haven't tested it.

注意:我希望这对你有所帮助,尽管我还没有测试过。