douhuai2015 2017-02-24 03:07
浏览 32
已采纳

CakePHP链接插件下拉列表没有链接[重复]

This question already has an answer here:

I am trying to use the plugin Chained to restricted users from selecting a city for the wrong country. At the moment when I have no country selected it lets me choose from all the cities. But as soon as I select a country it will not let me select any cities. I've had this plugin working correctly using the code from the Chained website. My broken countries/cities version can be seen here login: guest password: password http://team.southpacificavionics.com/customers/add and my test version can be seen if you change "add" on that url to "test" (sorry I cant post more links). I've used ./cake bake to create my customers, countries and cities controllers, models, templates and key relationships.

You can see from this image that the cities are linked to countries

This is my add.ctp for customers

 <?php echo $this->Html->script('jquery.min'); ?>
 <?php echo $this->Html->script('jquery.chained'); ?>

<script type="text/javascript">
    $(document).ready(function () {
        $("#cities").chained("#countries");
    });
</script>

<script type="text/javascript">
    $(document).ready(function () {
        alert('java is working');
    });
</script>

<?php
/**
  * @var \App\View\AppView $this
  */
?>

<div class="customers form large-9 medium-8 columns content">
    <?= $this->Form->create($customer) ?>
    <fieldset>
        <legend><?= __('Add Customer') ?></legend>

        <?php
            echo $this->Form->input('country_id', ['options' => $countries, 'empty' => true,'id'=>'countries']);
            echo $this->Form->input('city_id', ['options' => $cities, 'empty' => true,'id'=>'cities']);

        ?>
    </fieldset>

    <?= $this->Form->end() ?>

This is my mysql code

CREATE TABLE IF NOT EXISTS `southpac_team`.`customers` (
  `id` INT NOT NULL,
  `country_id` INT NULL,
  `city_id` INT NULL,
  PRIMARY KEY (`id`))
ENGINE = InnoDB;

CREATE TABLE IF NOT EXISTS `southpac_team`.`countries` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `name` VARCHAR(100) NULL,
  PRIMARY KEY (`id`))
ENGINE = InnoDB;

CREATE TABLE IF NOT EXISTS `southpac_team`.`cities` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `country_id` INT NOT NULL,
  `name` VARCHAR(100) NULL,
  PRIMARY KEY (`id`))
ENGINE = InnoDB;
</div>
  • 写回答

1条回答 默认 最新

  • dstxpei5823 2017-02-24 05:43
    关注

    You don't add class at your city dropdown options yet you should add country id as class in city dropdown

    pic

    How to add class in CakePHP Dropdown

    $items = $this->Cities->find('all')->all()->toArray();
            $cities = [];
            foreach ($items as $key => $value) {
                  $cities[$key]['value'] = $value['id'];
                  $cities[$key]['text'] = $value['indent_no'];
                  $cities[$key]['class'] = $value['country_id'];
            }
    

    for more check extra attribute in dorpdown

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog