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 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?