2011-08-16 35 views
0

我试图使用JQuery的自动完成视图助手Zend框架,在这里我简单的视图代码:Zend框架自动完成的jQuery UI表单辅助问题

echo $this->autoComplete("brand", 
          "", 
          array(
          'source' => $this->url(
             array('controller' => 'json', 'action' => 'brands'), 
             'default', 
             true), 
          'minLength' => '2' 
)); 

这里的JS输出码:

<script type="text/javascript"> 
//<!-- 
$(document).ready(function() { 
$("#brand").autocomplete({"source":"\/json\/brands","minLength":"2"}); 
}); 
//--> 
</script> 

ZF转义源URL(“/ json/brands”)。我在官方文档中发现了这个:

数据被转换为JSON,因此请确保使用Zend_Json_Expr类将可执行javascript标记为安全。

但我需要把源url作为参数。我该怎么做?

回答

0

我找到了!我必须把网址放在新的Zend_Json_Expr()中:

echo $this->autoComplete("brand", 
          "", 
          array(
          'source' => new Zend_Json_Expr('"'.$this->url(
             array('controller' => 'json', 'action' => 'brands'), 
             'default', 
             true).'"'), 
          'minLength' => '2' 
));