我使用KoGrid来制作我的自定义Ajax网格。我不知道如何将模型元素传递给一些javascript方法来生成自定义模板。
我试过这样做,但不工作:
PluginGrid.AjaxUrl("MyControler/GetGrid").Columns(
[
{ field: "UserName", displayName: "Model", width: "*", cellClass: "text-center", headerClass: "grid_width_270", cellTemplate: PluginHelpers.HtmlUserInformation($parent.entity, true) },
{ field: "StatusId", displayName: "Status", width: "*", cellClass: "text-center", headerClass: "text-center" }
]).Show("grid");
});
这实际上是KoGrid的包装器。我想把数据模型传递给Js方法:
PluginHelpers.HtmlUserInformation($parent.entity, true) }
当我这样做的时候,我收到了$parent变量的一些未定义的错误。
请建议,
最后我找到了一个解决方案:
<template id="XXX">
<div data-bind="html: PluginHelpers.HtmlUserInformation($parent.entity, true)">
</div>
</template>
然后
PluginGrid.AjaxUrl("Controller/GetGrid").Columns(
[
{ field: "UserName", displayName: "Model", width: "*", cellClass: "text-center", headerClass: "grid_width_270", cellTemplate: $("#XXX").html() },
{ field: "StatusId", displayName: "Status", width: "*", cellClass: "text-center", headerClass: "text-center" }
]).Show("grid");
这是我能找到的最好的解决方案....