如何让 Laravel Nova 的 select filter 的 value 值能支持中文?
/**
* Get the filter's available options.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function options(Request $request)
{
return [
'支持中文做key值'=>'但是value值就不支持中文了',
];
}
如果options数组的value值使用中文会报错
vendor.js?id=9e454f3261418eb9bca1:1 DOMException: Failed to execute 'btoa' on 'Window': The string to be encoded contains characters outside of the Latin1 range.
百度了下,在简书上找到一个帖子 :在Web前端还可以这样实现Base64
其实btoa只能转换占一个字节宽度的字符,就是Latin1字符集(它是ASCII的超集)。而中文汉字是被编码成占两个或以上个字节的。所以btoa方法无法对中文进行操作,于是就报了上面看到的错误。
不怎么会vue.js,不知道怎么去修改或重写对应的btoa方法,所以发帖请教。
目前只能绕开编码的问题,value使用中间key值来解决这个问题
public function apply(Request $request, $query, $value)
{
$array = [
'中间key值'=>'你需要的中文value'
];
return $query->where('title',$array[$value]);
}
public function options(Request $request)
{
return [
'支持中文做key值'=>'使用非中文的中间key值',
];
}