0

私のfueluxデータグリッドは、バックボーンレンダリング関数内でこのように見えます

    var dataSource = new StaticDataSource({
            columns: [
                                     {
                                           property: 'id',
                                           label: 'id',
                                          sortable: true
                                     },
                {
                    property: 'name',
                    label: 'groups',
                    sortable: true
                },
                {
                    property: 'name',
                    label: 'Roles',
                    sortable: true
                }
            ],
            data: this.collection,
            delay: 250
        });
        $('#sectionName').html('Groups');
        $('#MyGrid').datagrid({
            dataSource: dataSource,
            stretchHeight: true
        });

this.collection は次のように json を返します

[
{
    "id":1,
    "roles":[
                {"id":1,"authority":"ROLE1"},
                {"id":2,"authority":"ROLE2"},
                {"id":3,"authority":"ROLE3"}
            ],
    "groups":[
                {"id":1,"name":"A"},
                {"id":2,"name":"B"},
                {"id":3,"name":"C"}
          ]
},
{
    "id":2,
    "roles":[
                {"id":5,"authority":"ROLE4"},
                {"id":5,"authority":"ROLE5"},
                {"id":6,"authority":"ROLE6"}
            ],
    "groups":[
                {"id":4,"name":"D"},
                {"id":5,"name":"E"},
                {"id":6,"name":"F"}
          ]
}

]

Fuelux データグリッドに列 ID、役割、グループを持たせたい。以下のようになります。

    id        roles                        groups
    1         role1, role2 , role3          A, B, C
    12        role3, role4 , role5          D, E, F

このようなフォーマッタ関数を書き込もうとしましたが、うまくいきませんでした

 var dataSource = new StaticDataSource({
        columns: [
            {
                property: 'id',
                label: 'id',
                sortable: true
            },
            {
                property: 'name',
                label: 'groups',
                sortable: true
            },
            {
                property: 'name',
                label: 'Roles',
                sortable: true
            }
        ], 

       formatter: function (items) {
                $.each(items, function (index, item) {
                                    item.roles= //string made from groups with comma
                    item.groups= //string made from roles with comma

            },
        data: this.collection,
        delay: 250
    });

    $('#MyGrid').datagrid({
       //as above
    });
  formatter: function (items) {
                $.each(items, function (index, item) {
                   item.roles= //string of roles made from roles with comma
                                   item.groups= /string of groups made from groups with comma 
                });
            },

ここで誰かが私を助けてくれれば、とても助かります。

4

2 に答える 2

1

列定義の場合、それぞれpropertyがデータソースから返されるプロパティ名と一致する必要があります。これを試して:

{
    property: 'id',
    label: 'ID',
    sortable: true
},
{
    property: 'roles',
    label: 'Roles',
    sortable: true
},
{
    property: 'groups',
    label: 'Groups',
    sortable: true
}
于 2013-04-09T09:33:36.920 に答える
1

私は次のように私の問題を解決することができました

 formatter: function (items) {
                $.each(items, function (index, item) {
                    var roleCell = new app.RoleSupplier({ model: item      });
                    roleCell.render();
                    item.roles = roleCell.$el; //set property name above to roles
                });
            },

次に、以下のように RoleSupplier を作成しました

 app.RolesSupplier = Backbone.View.extend({
    template: _.template($('#roles-cell-template').html()),
    render: function (eventName) {
        this.$el.html(this.template(this.model.toJSON()));
    }
});

以下のようにテンプレートを作成しました

 <script type="text/template" id="roles-cell-template">
        <div>
            <@ _.each(roles.toJSON(), function( role, index, list ){ @>
                <@ if(index < (list.length - 1)) { @>
                    <@=role.authority + ','@>
                <@ } else { @>
                    <@=role.authority@>
                <@ } @>
            <@ }); @>

        </div>  
    </script>    

これは私にとってはうまくいきました。しかし、fuelux のユーザーが理解しなければならないことは次のとおりです。

  • プロパティ名をjsonのキーの名前に設定して、値を設定できます

    property:'id', label:'ID' // id 値を列名 ID に設定します

  • json 値があり、それらを特定の方法で表示したい場合、またはセルに html を表示できない場合は、以下のようにフォーマットします。

    formatter: function (items) {
                    $.each(items, function (index, item) {
                         item.yourPropertyName1= format your html here that you want  appear in label1
                         item.yourProeprtyName 2= fromat your html like button , anything you want inside column cell of label2                 
                    });
                },
    
于 2013-04-10T11:10:56.187 に答える