0

:ここに画像の説明を入力

http://en.wikipedia.org/wiki/7 ユーザーが式 1 のリンクをクリックすると、代わりにリダイレクトしたい http://en.wikipedia.org/wiki/Formula 1

ここで、7 はフォーミュラ 1 の ID です。

私のJSON応答は以下のようなものです

  {"rows":[{"id":7,"person":"Michael Schumacher","type":"Sport","name":"Formula 1"},
          {"id":8,"person":"Lukas Podolski","type":"Sport","name":"Football"},
          {"id":9,"person":"Blaise Pascal","type":"Sport","name":"mathematics"},
          {"id":6,"person":"Albert Einstein","type":"Sport","name":"Physics"}]}

jqgridのコードは

     jQuery("#list2").jqGrid({
     url:"***.****",
        datatype: "json",
            mtype: 'GET',
            colNames:['Name','Category','Subcategory'],
            colModel:[
               {name:'person',index:'person', width:150},
               {name:'type',index:'type', width:150},
               {name:'name',index:'name', width:150,        
                   formatter: function (cellvalue, options, rowObject) {
                        var cellPrefix = '';
                        return cellPrefix + '<a href="http://en.wikipedia.org/wiki/' + cellvalue + '">' +
                               cellvalue + '</a>';
                    }}

            ],

            width:"647px",
            caption:"How to create custom Unobtrusive links"

        });
4

2 に答える 2

2

cellvalueカスタムフォーマッタのコード内を次のように置き換えるだけですoptions.rowId

formatter: function (cellvalue, options) {
    return '<a href="http://en.wikipedia.org/wiki/' + options.rowId + '">' +
            cellvalue + '</a>';
}

さらに JSON データを修正し、"name":"Formula 1"代わりに使用する必要があります (列"name"="Formula 1"のすべてのデータで同じ)。"name"おそらく、スタックオーバーフローで質問を準備する際の入力エラーです。

于 2013-09-20T11:20:51.823 に答える