Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/443.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 检查通过视图传递的数据在laravel中不为空_Javascript_Php_Laravel 4 - Fatal编程技术网

Javascript 检查通过视图传递的数据在laravel中不为空

Javascript 检查通过视图传递的数据在laravel中不为空,javascript,php,laravel-4,Javascript,Php,Laravel 4,我使用的是Laravel4,我想通过视图传递数据。 我在控制器中使用了此代码 $view = View::make('settings.editEvent'); $view->bounderyData = $bounderyData; 我想检查视图设置/editEvent.blade.php中是否存在此数据 我试过用这个 <script> if('{{$bounderyData.length()}}'!=null) console.log('exists')

我使用的是Laravel4,我想通过视图传递数据。 我在控制器中使用了此代码

$view = View::make('settings.editEvent');
$view->bounderyData = $bounderyData;
我想检查视图设置/editEvent.blade.php中是否存在此数据

我试过用这个

<script>
   if('{{$bounderyData.length()}}'!=null)
      console.log('exists');
</script>

如何检查是否存在?

不要将数据分配给视图变量,而是使用
传递数据,因为Laravel要求您使用:

$view = View::make('settings.editEvent')
    ->with('bounderyData', $bouderyData);

实际上,这两个代码段的工作方式相同。您可以使用
with()
方法传递数据,也可以将数据指定给view as属性。所以这并不重要。但看起来您使用了一些奇怪的语法,因为您试图在Blade echo语句中使用点语法访问方法
length()
。尝试:

if({{count($bounderyData)}}!=null)
  console.log('exists');
或者类似的东西。请记住,
{{}}
中的所有内容都将由PHP响应。所以,如果您有某种数组,您可能需要计算元素的数量,或者将其转换为JSON,然后在Javascript中对其进行解码。如果您仍然有问题,请告诉我们问题所在

if({{count($bounderyData)}}!=null)
  console.log('exists');