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 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥15 (关键词-阻抗匹配,HFSS,RFID标签天线)
  • ¥15 机器人轨迹规划相关问题
  • ¥15 word样式右侧翻页键消失