Skip to content

Commit

Permalink
修复表格规格选择器存在多个0开头选项时选中功能异常问题
Browse files Browse the repository at this point in the history
  • Loading branch information
jqhph committed Mar 8, 2021
1 parent bc6dbb2 commit 1f2a7eb
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion resources/views/grid/selector.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<ul>
@foreach($selector['options'] as $value => $option)
@php
$active = in_array($value, \Illuminate\Support\Arr::get($selected, $column, []));
$active = in_array((string) $value, \Illuminate\Support\Arr::get($selected, $column, []), true);
@endphp
<li>
<a href="{{ $self->url($column, $value, true) }}"
Expand Down
8 changes: 6 additions & 2 deletions src/Grid/Tools/Selector.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ public function parseSelected()

foreach ($selected as &$value) {
$value = explode(',', $value);

foreach ($value as &$v) {
$v = (string) $v;
}
}

return $this->selected = $selected;
Expand Down Expand Up @@ -182,8 +186,8 @@ public function url($column, $value = null, $add = false)
return $this->request->fullUrlWithQuery($query);
}

if (in_array($value, $options)) {
Helper::deleteByValue($options, $value);
if (in_array((string) $value, $options, true)) {
Helper::deleteByValue($options, (string) $value, true);
} else {
if ($add) {
$options = [];
Expand Down
5 changes: 3 additions & 2 deletions src/Support/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -417,13 +417,14 @@ public static function exportArrayPhp(array $array)
*
* @param array $array
* @param mixed $value
* @param bool $strict
*/
public static function deleteByValue(&$array, $value)
public static function deleteByValue(&$array, $value, bool $strict = false)
{
$value = (array) $value;

foreach ($array as $index => $item) {
if (in_array($item, $value)) {
if (in_array($item, $value, $strict)) {
unset($array[$index]);
}
}
Expand Down

0 comments on commit 1f2a7eb

Please sign in to comment.