[英]Yii2 modal with composite key
Can anyone help me with the composite key? 有人可以帮助我使用组合键吗? I am not able to function properly.
我无法正常运行。
function init_click_handlers(){
$(".button-endereco").click(function(e) {
var fcodigo = $(this).closest("tr").data("codigo");
var fcodigopessoa = $(this).closest("tr").data("codigopessoa");
var map = {codigo: $(this).closest("tr").data("codigo"), codigopessoa: $(this).closest("tr").data("codigopessoa")};
$.get(
"update ",
{
codigo: fcodigo
codigopessoa: fcodigopessoa
},
function (data)
{
$("#endereco-modal").find(".modal-body").html(data);
$(".modal-body").html(data);
$("#endereco-modal").modal("show");
}
);
});
}
init_click_handlers(); //first run
$("#endereco_id").on("pjax:success", function() {
init_click_handlers(); //reactivate links in grid after pjax update
});
$url = Yii::$app->urlManager->createUrl('../endereco/update?codigo='.$dataProvider->codigo.'&codigopessoa='.$dataProvider->codigopessoa);
If you want refer to the data inside a $dataProvider you firts need to get the model you need. 如果要引用$ dataProvider中的数据,则需要获取所需模型。 In dataProvider all the models relate to your query are available and you can get from the models array the specific model accessing by the a proper index eg:
在dataProvider中,与您的查询相关的所有模型均可用,并且您可以通过适当的索引从models数组中获取特定模型,例如:
myModel = $dataProvider->models[yourIndex]
myValue = myModel->myField
In your case foe example you could get the vaue in this way 以您的情况为例,您可以通过这种方式获得价值
myModel = $dataProvider->models[0]:
myValue = myModel->codigo;
I got 90% of the response, but could not catch my composite key (password, codigopessoa), forced the values to test the function and it worked. 我得到了90%的响应,但无法捕获我的复合键(密码,codigopessoa),强制使用这些值来测试该函数,并且该函数有效。 So lack I get the column values (composite key).
因此,我缺少列值(复合键)。
function init_click_handlers(){
$(".button-endereco").click(function(e) {
fcodigo = $(this).closest("tr").data("codigo");
fcodigopessoa = $(this).closest("tr").data("codigopessoa");
$.ajax({
url: "'.Yii::$app->urlManager->createUrl('endereco/update').'",
type: "GET",
data: {"codigo": parseInt(17), "codigopessoa":parseInt(8)},
dataType: "html",
success: function(data) {
$("#endereco-modal").find(".modal-body").html(data);
$(".modal-body").html(data);
$("#endereco-modal").modal("show");
}
});
});
}
init_click_handlers(); //first run
$("#endereco_id").on("pjax:success", function() {
init_click_handlers(); //reactivate links in grid after pjax update
});
[100% working] Finally got it, for those who want to use the Gridview (kartik) with composite key follows the code: [100%工作]终于明白了,对于那些想使用带有复合键的Gridview(kartik)的人,代码如下:
function init_click_handlers(){
$(".button-endereco").click(function(e) {
chave = $(this).closest("tr").data("key");
$.ajax({
url: "'.Yii::$app->urlManager->createUrl('endereco/update').'",
type: "GET",
data: {"codigo": parseInt(chave["codigo"]), "codigopessoa":parseInt(chave["codigopessoa"])},
//data: {keylist: parseInt(keys)},
dataType: "html",
success: function(data) {
$("#endereco-modal").find(".modal-body").html(data);
$(".modal-body").html(data);
$("#endereco-modal").modal("show");
}
});
});
}
init_click_handlers(); //first run
$("#endereco_id").on("pjax:success", function() {
init_click_handlers(); //reactivate links in grid after pjax update
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.