当我使用String作为参数调用函数时出现javascript错误

时间:2017-11-16 10:31:01

标签: javascript php laravel

你能告诉我自己做得不好吗?我正在通过laravel管理的html页面调用javascript函数,但当我在引号之间放入Uncaught SyntaxError: missing ) after argument list的返回时,它会一直返回Uncaught SyntaxError: Invalid or unexpected token$connexio->dispositiu->descendents()["credencial"]

$connexio->dispositiu->descendents()["credencial"]告诉我:

return [
        [
            'id' => 22,
            'tipus' => 'Antena',
            'name' => 'Ubikiti',
            'tab' => 0,
            'credencial' => "'".Dispositiu::find(22)->credencial->__toString()."'"
        ],......

Dispositiu::find(22)->credencial->__toString()让我回到下一个:

{
    $text = "IP: $this->ip:$this->port\n".
        "IP Interna: $this->ip_interna\n".
        "User: $this->user\n".
        "Password: $this->pass\n".
        "Observacions: $this->observacio\n\n".
        $this->credenciable->__toString();
    return $text;
}

下一个代码在html页面中。

<?php $comptador = 2 ?>
@foreach($connexio->dispositiu->descendents() as $fill)
    <tr class="<?php if($comptador%2 == 0) echo 'par'; else echo'impar'; $comptador++;?>"
        title="{{ $fill["credencial"] }}">
        <td class="connexioTab{{$fill["tab"]}} ">{{$fill["tipus"]}}</td>
        <td class="connexioTab{{$fill["tab"]}} ">{{$fill["name"]}}</td>
        <td>
            <a onclick="mostraInformacio({{ $fill["credencial"]}})"><i class="fa fa-unlock" aria-hidden="true"></i></a>
        </td>
    </tr>
@endforeach

javascript函数是:

function mostraInformacio(info){
    if(typeof info === "undefined") info = 'No credential found!';
    console.log(info);
    alert(info);
}

你能告诉我这是什么错误吗?当我执行dd($fill["credencial");时,它返回String,但在6个引号""" String.... """之间。可能是错误吗?

1 个答案:

答案 0 :(得分:0)

我发现了错误。这是在我的PHP代码中,'{divpositiu-&gt; credencial'的public static IEnumerable<string> ToIds(this IEnumerable<string> teamIds, IEnumerable<Team> modifiedTeams, IEnumerable<Team> allTeams) { var modifiedTeamsLookup = modifiedTeams.ToDictionary(team => team.Id); var allTeamsLookup = allTeams.ToDictionary(team => team.Id); return teamIds .SelectMany(teamId => teamId.ToDriverIds(modifiedTeamsLookup, allTeamsLookup); } 方法具有类似这样的代码:

__toString()

我更改了表单以输入新行:

$text = "IP: $this->ip:$this->port\n".
    "IP interna: $this->ip_interna\n".
    "User: $this->user\n".
    "Pass: $this->pass\n".
    "Observació: $this->observacio\n".
    $this->credenciable->__toString();
return $text;

它有效,我可以看到字符串进入警告javascript。

感谢所有试图帮助我的人。