1

我需要在 ojTable 中显示内部 pojo 字段的值。

这是 bakcend 代码:

public class Profile implements Serializable {
private String descr;
private Location location;   // I need to show on table -> ojtable
}


public class Location implements Serializable {
private Long id;
private String locationName;
}

和html代码:

<table id="table" summary="Subscriber List"
data-bind="ojComponent: {component: 'ojTable',
emptyText: 'No Data',
data: dataSource,
selectionMode: {row: 'single'},
columnsDefault: {sortable: 'enabled'},
dnd: {reorder: {columns: 'enabled'}},
columns:
[{headerText: 'Description',
field: 'description'},
{ headerText: 'Location Name',
field: 'location.locationName'}  ----->>>>>> This one is not working
],
rootAttributes: {'style':'width: 100%; height:100%;'}}">
</table>

在这种情况下,我有 Profile 对象,需要在 html 端到达内部 Location 对象的 locationName 字段。我尝试了 dot notaion -> location.locationName 但它不起作用。

我还尝试了自定义渲染器/敲除模板,但它们都需要一个新的 js 函数用于我需要显示的每个字段,我认为这不是通用的。

请帮助我实现这一目标。

提前致谢。

4

1 回答 1

2

据我了解,显示和组织 ojTable 的最流畅方式是使用自定义行模板,如示例中所示:

<script type="text/html" id="row_tmpl">

    <tr>
        <td data-bind="text: location.locationName">
        </td>
        <td data-bind="text: location.id">
        </td>
    </tr>

</script>

请注意,元素的顺序应符合 ojTable 列名称的顺序。

于 2017-01-31T12:36:09.460 回答