我正在使用jQCloud实用程序生成词云,但是我做不到。
这是我的控制器代码:
public function consultar(Request $request)
{
$entidad = $request['entidad'];
$result = exec("python3 /root/TFGArchivos/ScriptFinal.py -o $entidad");
$opiniones = array();
$palabras = array();
foreach (json_decode($result) as $valor) {
if ($valor == 1 || $valor == -1) {
$opiniones[] = $valor;
}
else {
$palabras[] = $valor;
}
}
return view("resultado_entidad", ['entidad'=>$request['entidad'],"palabras"=>$palabras]);
}
这是我的观点代码:
<div id="nube" name="nube" style="width: 550px; height: 350px; position: relative;"></div>
<script>
window.onload = function ()
{
var array = <?php echo json_encode($palabras); ?>;
$("#nube").jQCloud(array);
}
</script>
foreach之后$ palabras的内容为:
Array ( [0] => {text: 'deben', weight:1} [1] => {text: 'acabo', weight:1} [2] => {text: 'texto', weight:1} [3] => {text: 'arrepiento', weight:1} [4] => {text: 'quichua', weight:2} ... ) ;
jQCloud调用之前的数组内容为:
{text: 'cs', weight:1},{text: 'adelante', weight:2},{text: 'acosar', weight:1},{text: 'traves', weight:1},{text: 'aviso', weight:1},{text: 'voy', weight:8},{text: 'priv', weight:1}...
我在这里发布两者的简短版本,因为它们太长了。
如果我用Javascript声明一个数组并将该数组传递给jQcloud,它会完美地工作。
谢谢!
答案 0 :(得分:0)
尝试一下
Set xName = ActiveSheet.Range("B3", ActiveSheet.Range("B2").End(xlDown))
还要在包含js序列时检查它,它应该是
<div id="nube" name="nube" style="width: 550px; height: 350px; position:
relative;"></div>
<script>
window.onload = function ()
{
var array = [<?php echo json_encode($palabras); ?>];
$("#nube").jQCloud(array);
}
</script>