【发布时间】:2026-01-27 21:40:02
【问题描述】:
我正在尝试使用链接到限制用户为错误国家/地区选择城市的插件。在我没有选择国家的那一刻,它让我从所有城市中进行选择。但是一旦我选择了一个国家,它就不会让我选择任何城市。我已经使用来自 Chained 网站的代码让这个插件正常工作。 我的破碎国家/城市版本可以在这里看到 登录:访客 密码:密码 http://team.southpacificavionics.com/customers/add 如果您将该网址上的“添加”更改为“测试”,则可以看到我的测试版本(对不起,我不能发布更多链接)。 我使用 ./cake bake 来创建我的客户、国家和城市控制器、模型、模板和关键关系。
You can see from this image that the cities are linked to countries
这是我给客户的 add.ctp
<?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() ?>
这是我的mysql代码
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;
【问题讨论】:
标签: php jquery mysql cakephp chained