Social Engine Zend Framework - 国家/州/城市的动态 Ajax 下拉菜单

发布于 2024-09-28 09:40:43 字数 285 浏览 4 评论 0原文

我正在使用基于 Zend Framework 和 Smarty Template 的 Social Engine。

我需要为个人资料页面创建自定义功能,其中我需要基于 Ajax 的动态国家/州/城市选择,例如

国家下拉菜单 ->选择某个国家时,State 将显示属于所选国家和 State 选择 ->将显示相关城市。我的国家/州和城市有单独的表格。

任何人都可以帮助我们或者可以提供一些参考/示例吗?

我不知道如何进行 Ajax 调用并用它呈现我的视图!

问候 !

I am working with Social Engine which is based on Zend Framework and Smarty Templates.

I need to make custom functionality for profile page, where I need Ajax based Dynamic Country / State / City selections like

Dropdown for Country -> on selection of some country, State will display belonging to selected country and State selection -> related Cities will display. I have separate tables for my country/state and city.

Anybody can help us or can provide some reference / examples for the same?

I don't know, how to make Ajax calls and render my views with this !

Regards !

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

jJeQQOZ5 2024-10-05 09:40:43

请参阅下面的代码:

给出我的项目加载段、船舶类型子段的代码。与国家/地区相同,状态

首先像往常一样使父下拉菜单如下:

 <?php 

  echo $this->formSelect('segment','none',array('class' => 'select-advanced', 'width' => '250'),$this->arrInput['shiptype']);  

?>

这里arrInput ['shiptype']来自controllar

为您表单上的子下拉菜单创建一个div

现在将jquery代码放在您的表单上:

<script>

var base_path = "<?php echo $this->baseUrl();?>/";

$('#segnam').change(function()
{

var segId=document.getElementById('segment').value;

      $.ajax({
                 url:  base_path + "search/subseg/",
                data: "segId="+segId,
                type: 'GET',
             success: function (resp) { document.getElementById('subsegdiv').innerHTML=resp;},
               error: function(e){  alert('Error: '+e);  }  
            });
});
</script>

现在为子下拉菜单您的控制器执行一个操作:

public function subsegAction()
    {   
        $request = $this->getRequest();
        $objShiptype = new Shiptype();   
         $segId=$request->getParam('segId');  
        $SubSegArr=$objShiptype->getSubSegment($segId);
        $this->_helper->layout->disableLayout();
            $this->getResponse()->setHeader('Content-Type', 'text/javascript');
            $this->view->subseg=$SubSegArr;

    }

现在为上述操作创建一个视图:

使用 html 使 html 下拉(子)从子段控制器获取数据

,请参阅段 = 国家/地区
subseg = 城市的州

遵循相同的操作并再次查看和 jquery 代码。

如果不清楚,您可以随时询问。我有这个任务。这很棘手:)

See code below:

giving code from my project loads segment, sub-segments of ship type. same as country ,state

first make parent drop down as usual like this :

 <?php 

  echo $this->formSelect('segment','none',array('class' => 'select-advanced', 'width' => '250'),$this->arrInput['shiptype']);  

?>

here arrInput['shiptype'] is from controllar

make a div for child drop down on ur form

Now put below jquery code on ur form:

<script>

var base_path = "<?php echo $this->baseUrl();?>/";

$('#segnam').change(function()
{

var segId=document.getElementById('segment').value;

      $.ajax({
                 url:  base_path + "search/subseg/",
                data: "segId="+segId,
                type: 'GET',
             success: function (resp) { document.getElementById('subsegdiv').innerHTML=resp;},
               error: function(e){  alert('Error: '+e);  }  
            });
});
</script>

now for child drop dowm in yor controllar make a action :

public function subsegAction()
    {   
        $request = $this->getRequest();
        $objShiptype = new Shiptype();   
         $segId=$request->getParam('segId');  
        $SubSegArr=$objShiptype->getSubSegment($segId);
        $this->_helper->layout->disableLayout();
            $this->getResponse()->setHeader('Content-Type', 'text/javascript');
            $this->view->subseg=$SubSegArr;

    }

now make a view for above action:

make html drop down (child) using html take data from subseg controller

here refer segment = country
subseg = state

for city follow same make a action and view and jquery code again.

If not clear u are free to ask. I have donw this task. It's tricky :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文