1

環境:

1.EasyUI Datagrid
2.jsp(s2sh)
3.mysql 
//until now i can populate the datagrid plugin with json object normally but a 
  small issue.

説明:

以下のように、サーバーから Json-data-object が返されました。

{"total":28,"rows":[{"productid":"1","attr":{"size":"10dc","color":"red&yellow"},
                    {"productid":"2","attr":{"size":"102dc","color":"green&null"}

プラグインで:

$(document).ready(function(){
      $('#tt').datagrid({  
        url:'loadVerifyStream.eAction',
        pagination:true,
        columns:[[  
                {field:'productid',title:'Product ID',width:100},  
                {field:'?????',title:'Product Size',width:250},  
                {field:'?????',title:'product Color',width:100},
       ]]  

}); });

「サイズ」と「色」属性をグリッドに出力できません。試してみました

{field:'attr.size',title:'Product Size',width:250},
{field:'attr.color',title:'product Color',width:100},

仕事がありません。

誰もこれを解決する方法を知っていますか? 前もって感謝します。

//----------------------------------------- 私はこの問題を理解したと思いますすでに。

DataGrid の API を参照してください。

{field:'color',title:'product Color',width:100,
   formatter:function(val,rec){
   return rec.attr == null ? "":rec.attr.color;

}}

4

2 に答える 2

3

これはより一般的な解決策です。

あなたのjsonオブジェクトが次のようになっているとします:

[{id:3,client:{name: "John",city:'New York'},
[{id:4,client:{name: "Paul",city:'Paris'}]

fomatter 関数でフィールド名を取得するには、次のマークアップを使用します。

<table id="dg">
    <thead>  
      <tr>
        <th field="id" width="50">ID</th>
        <th field="not used" formatter="(function(v,r,i){return formatColumn('client.name',v,r,i);})" width="50">Client name</th>
        <th field="not used" formatter="(function(v,r,i){return formatColumn('client.city',v,r,i);})" width="50">Client city</th>
      </tr>  
    </thead>  
</table>

次に、formatColumn を定義します

function formatColumn(colName, value, row, index) {
    return eval("row."+colName");
}
于 2012-10-17T08:47:06.513 に答える
1

または、このハックを使用することもできます (easyui バージョン 1.3.1 の場合)。ファイル jquery.easyui.min.js の 7982 行目に移動すると、次のコードが含まれているはずです。

cc.push(col.formatter(_5c5,_5c2,_5c1));

このコードに置き換えます

 cc.push(col.formatter(_5c5,_5c2,_5c1,_5c4));

次に、次のようにフォーマッタを定義します。

function formatColumn(value, row, index, field) {
    // field is the field name defined for this column
    return row[field]; // or anything you want
}
于 2012-11-22T21:52:15.210 に答える