我有这样的网格
@(Html.Kendo().Grid(Model.Differences)
.Name("formDifferencesList")
.HtmlAttributes(new { @class = "fullScreen" })
.Columns(columns =>
{
columns.Bound(e => e.Property);
columns.Bound(e => e.FieldPath);
columns.Bound(e => e.FieldType);
columns.Bound(e => e.Type);
columns.Bound(e => e.LeftValue);
columns.Bound(e => e.RightValue);
})
.Pageable()
.Sortable()
.Scrollable()
.Selectable()
.Resizable(resize =>
resize.Columns(true))
.Groupable()
.Filterable()
.DataSource(dataSource =>
dataSource.Ajax()
.PageSize(25)
.ServerOperation(false)
.Model(model => model.Id(e => string.Format("{0}{1}", e.Property, e.FieldPath)))))
RightValue
和LeftValue
是Object
类型的实例,它可以是原始值(如int
,string
),但它也可以是采集。如果它是一个集合,我想使用Kendo ListView
来表示它。我该怎么做?
我试图绑定到DataBound事件
.Events(events => events.DataBound("onDifferencesDataBounded"))
将ClientTemplate添加到网格
columns.Bound(e => e.LeftValue).ClientTemplate("<div class='leftValueView'></div>");
然后在js函数内部尝试应用模板
<script type="text/javascript">
function onDifferencesDataBounded() {
$.each($('.leftValueView'), function () {
var grid = $('#formDifferencesList').data().kendoGrid;
var row = $(this).closest('tr');
var dataItem = grid.dataItem(row);
$(this).kendoListView({
dataSource: { data: dataItem },
template: kendo.template($("#leftValueTemplate").html())
});
});
}
</script>
<script type="text/x-kendo-template" id="leftValueTemplate">
// Not sure what should I do here?
</script>
答案 0 :(得分:1)
当你在那里放置断点时, dataItem.LeftValue 或RightValue(如Array)中是否有任何内容?
var dataItem = grid.dataItem(row); //&lt; -breakpoint传递那条线
如果有数组如 [1,3,4,5] ,那么您可以尝试在模板中使用#= data#