0

通常、次のような onSelectRow 関数を呼び出します。

$("#imports_grid").jqGrid({
    // jqGrid settings
    url: url,
    datatype: "json",
    colNames: cnames,
    colModel: cmodel,
    onSelectRow: function() {
      // Code
    },
});

私のPHPスクリプトは、json_encode()を使用してjqGrid設定を出力するため、次のようになります

$script = '$("#imports_grid").jqGrid(' . json_encode($js_settings) . ');';
// echo $script;

この場合、onSelectRow の機能は機能しません。

onSelectRow 内で関数を起動する別の方法はありますか?

4

1 に答える 1

1

You don't need to mix HTML code and JavaScript code inside of PHP script. Instead of that you can place <script> element

<script type="text/javascript" src="theURL.js"></script>

in the PHP script. The JavaScript code you can place in the .JS file.

UPDATED: You can make of cause a mix between inline JavaScript code where you set some global variables and the JS file where you use the variables:

in PHP code you use

<script type="text/javascript">
    var MYGLOBALSETTINGS = {
        cnames: ["Column 1", "Column 2", ...],
        cmodel: [{...}, {...}...],
        url: "myUrl"
    };
</script>
<script type="text/javascript" src="my.js"></script>

and in my.js you just use MYGLOBALSETTINGS.cnames and MYGLOBALSETTINGS.cmodel

$("#imports_grid").jqGrid({
    // jqGrid settings
    url: MYGLOBALSETTINGS.url,
    datatype: "json",
    colNames: MYGLOBALSETTINGS.cnames,
    colModel: MYGLOBALSETTINGS.cmodel,
    onSelectRow: function() {
      // Code
    },
});
于 2012-12-01T10:41:06.563 に答える