2015-12-21 42 views
0

任何人都可以用組合鍵幫我嗎?我無法正常工作。帶複合鍵的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); 
+0

你能進一步解釋它是如何的不正常? –

+0

通過這種方式的腳本,表單看起來破損並且在檢查的方式中使用了google chrome來控制javascript中的錯誤。但是,如果我在代碼後面加逗號:fcodigo發生錯誤,但_form顯示爲空白。 –

回答

0

如果你想引用$ dataProvider中的數據,你需要獲得你需要的模型。在數據提供程序所有的模型涉及到查詢可用,您可以從模型陣列獲取的具體型號通過適當的指標如訪問:

myModel = $dataProvider->models[yourIndex] 

myValue = myModel->myField 

你的情況,敵人例如,你可以得到vaue這樣

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

他們是我需要的兩個模型,我實際上正在嘗試使用帶有組合鍵的模態_form。 直到你到達那裏,但腳本錯誤,並干擾其他模塊,如kartik。 –

0

我得到了90%的響應,但沒能趕上我的組合密鑰(密碼,codigopessoa),迫使值來測試功能和它的工作。 所以缺乏我得到的列值(複合鍵)。

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 
}); 
+0

data:{「codigo」:parseInt(fcodigo),「codigopessoa」:parseInt(fcodigopessoa)}, 結果:GET http://sistema.iprem.com/endereco/update?codigo=NaN&codigopessoa=NaN 404(Not Found ) –

0

[100%的工作最後得到了它,對於那些誰想要使用的GridView(卡爾蒂克)複合鍵下面的代碼:

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