具有复合键的Yii2模态

任何人都可以帮我复合键吗? 我无法正常运作。

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); 

如果您想参考$ dataProvider中的数据,您需要获得所需的模型。 在dataProvider中,所有与您的查询相关的模型都可用,您可以从models数组中获取通过适当索引访问的特定模型,例如:

 myModel = $dataProvider->models[yourIndex] myValue = myModel->myField 

在你的情况下,你可以通过这种方式获得vaue

 myModel = $dataProvider->models[0]: myValue = myModel->codigo; 

我有90%的响应,但无法捕获我的复合键(密码,codigopessoa),强制值测试function,它的工作。 所以我得不到列值(复合键)。

 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%工作]终于明白了,对于那些想要使用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 }); 
Interesting Posts