- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
嗨,开发人员,我正在构建一个应用程序表单,用户可以在其中将数据输入到不同的字段中。应用程序的一部分是来自 https://github.com/wbraganca/yii2-dynamicform 的动态表单.现在在动态表单中,我有一个依赖下拉列表,但是当我单击 [+] 符号时,依赖下拉列表更改第一行而不是第二行的数据。
这是我的代码。
在我的 Controller 中
public function actionLists($name)
{
$countHs= Hs::find()
->where(['hscode'=> $name])
->count();
$Hs = Hs::find()
->where(['hscode'=> $name])
->all();
if($countHs > 0)
{
foreach ($Hs as $H)
{
echo "<option value='".$H->hsproduct."'> ".$H->hsproduct."</option>";
}
}else{
echo "<option> - </option>";
}
}
和我的表格
<div class="col-sm-6" style="width: 135px">
<?= $form->field($modelsItems, "[{$i}]hscode")->dropDownList(
ArrayHelper::map(Hs::find()->all(),'hscode','hsproduct'),
[
'prompt'=>'',
'onchange'=>
'$.get( "'.Url::toRoute('/hs/lists').'", { name: $(this).val() })
.done(function( data ) { $( "#'.Html::getInputId($modelsItems, "[{$i}]hsproduct").'" ).html( data ); } );'
])->label('HS.Code');
?>
</div>
<div class="col-sm-6" style="width: 135px">
<?= $form->field($modelsItems, "[{$i}]hsproduct")->dropDownList(
ArrayHelper::map(Hs::find()->all(),'hsproduct','hsproduct'),
[
'prompt'=>'',
])->label('HS.Product');
?>
</div>
我是新手,对不起我的英语
最佳答案
针对您的案例进行了更新。
我所做的是在 JS 文件 var i
中声明全局变量并分配 0
。第一个事件触发后,我将变量 i
增加一个。现在它在内存中包含 1。下次它将取 1 并再次加 1。等等:
var i = 0;
$(document).on('change', 'select', function(e) {
i++;
})
请注意,这只有在您在每一行中只选择一次并且您不会返回到特定行时才有效。如果您想做类似的事情,您应该获取元素 ID 的编号,解析为 float (而不是字符串)并将该编号用于您的事件脚本。
parseFloat($('#hs-0-hscode')[0].id.split('-')[1])
下面还有一个额外的解决方案(但不是根据您的)。以防万一。
使用 Inspect source
并查找输入字段的命名方式(名称或 ID)。比方说,我们有 name="hs-0-hscode"
。这只是为了你的 jQuery:
$(document).on('change', 'select', function(e) {
if ($(this)[0].id.indexOf('hscode') > 0) {
// Now you can use Ajax to get a list of items you want to show.
// Element itself can be reached: $(this).parent().parent().parent().children().eq(1);
// For example:
// var data = $.parseJSON(results);
// $.each(data, function(key, value) {
// $('#client-company_size')
// .append($("<option></option>")
// .attr("value", key)
// .text(value));
// });
}
});
关于php - 具有从属下拉列表的动态表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39665500/
我正在 Jenkins 中配置从 Linux 节点。这里的多个标签的正确语法(分隔符和转义)是什么? 最佳答案 您应该使用 whitespaces 分隔标签。如果标签包含空格,您应该引用它(单引号和双
我已经设置了 master(192.168.1.10) 和 slave(192.168.1.11) postgresql。登录slave postgresql报错: postgres@sonia-Sy
我支持由小型企业托管的应用程序,基于 Web 的 ROR 应用程序在后端使用 pgsql 数据库。 Postgres 设置为复制到异地备用服务器,据我所知它工作正常,当我查询远程服务器时它显示它正在恢
这个方法是我写的(和其他帖子差不多) public void update(string fileName, string sheetName) { string connString = c
我已经为 MySQL 服务器设置了复制。我可以使用复制用户/密码从从机连接到主服务器。我已经运行了从属 SQL 线程,但是从属 I/O线程未运行,使用“显示从属状态”检查时从属 I/O 状态为空。可能
在使用Jenkins Docker插件时,可能由于错误而导致无法启动群集。我没有注意,目前有数千个脱机节点无法启动。 底线-是否可以批量删除Jenkin中的节点(从属),清理所有脱机节点甚至删除所有节
我正在尝试在一个旧项目中引入持续集成,我们遇到了非常具体的情况 - 可以将 CI 服务器只放在我们在 CentOS 上运行的测试服务器上。服务器有很多未使用的 RAM 和 CPU 功能。 但是,我们需
我最近更改了我的 jenkins 机器使用的其中一个从属设备的 DNS cname 记录。进行更改后,我更新了节点中的信息,使其指向新名称。从那时起,jenkins slave 无法启动并出现以下错误
我需要创建在 Amazon EC2 上的 Windows VM 下运行的 Jenkins 代理云。 我对此的看法是简单的场景: 我有几个预配置的 AMI,每个虚拟机都有与我的项目之一匹配的特定环境。我
使用 Jenkins EC2 插件,我无法让我的 Jenkins 主服务器通过 SSH 连接到我的 Jenkins 从服务器。从站启动并正确配置,但是: INFO: Connecting to 10.
奇怪的问题,我在工作区中有两个项目: 项目A 项目B 在 projectA 的 pom.xml 中我添加了: groupid projectB version 当我构建应用程序并部署到 tomca
在我的 Jenkinsfile 中出现错误后,从属代理 pod 似乎总是很快就会死亡并消失。有没有办法在我身处其中时执行它并使其保持事件状态?我使用 Helm 在 Kubernetes 上运行 Jen
我是一名优秀的程序员,十分优秀!