如何在 underscore.js 模板中插入多个数据源?
How to insert multiple data sources in an underscore.js template?
我正在使用数据表和 underscore.js。这是我的数据表列:
{
data: 'date', searchable: false, orderable: false,
render: function (data, type, row, meta) {
return row.date;
}
},
{
data: 'routeSectionStepID', searchable: false, orderable: false,
render: function (data, type, row, meta) {
var structure = _.template($('#tmpl-actions').html()),
html = structure({ Id: data });
return html;
}
}
这是我的下划线模板:
<script id="tmpl-actions" type="text/html">
<form action="">
<% if (date == null){ %>
<input type="checkbox" name="process" value="<%= Id %>" id="checkbox" checked disabled/>Id: <%= Id %>
<% } else { %>
<input type="checkbox" name="process" value="<%= Id %>" id="checkbox" />Id: <%= Id %>
<% } %>
</form>
</script>
正如您在上面的 if 语句中看到的,我试图根据 'date' 列是否为空来设置复选框 enabled/disabled。显然,仅在 if 语句中键入 'date' 是行不通的。
我想我需要在我的第一个示例中使用 html = structure({ Id: data });
行来表示 Id: data
和 Date: data
但显然它们不能同时使用相同的 data
.
如何访问上一列的 date
数据并将其(与 routeSectionStepId
一起)传递到我的 _.template?
解决了
html = structure({ Id: data, Date: row.date });
和
<% if (Date == null){ %>
我正在使用数据表和 underscore.js。这是我的数据表列:
{
data: 'date', searchable: false, orderable: false,
render: function (data, type, row, meta) {
return row.date;
}
},
{
data: 'routeSectionStepID', searchable: false, orderable: false,
render: function (data, type, row, meta) {
var structure = _.template($('#tmpl-actions').html()),
html = structure({ Id: data });
return html;
}
}
这是我的下划线模板:
<script id="tmpl-actions" type="text/html">
<form action="">
<% if (date == null){ %>
<input type="checkbox" name="process" value="<%= Id %>" id="checkbox" checked disabled/>Id: <%= Id %>
<% } else { %>
<input type="checkbox" name="process" value="<%= Id %>" id="checkbox" />Id: <%= Id %>
<% } %>
</form>
</script>
正如您在上面的 if 语句中看到的,我试图根据 'date' 列是否为空来设置复选框 enabled/disabled。显然,仅在 if 语句中键入 'date' 是行不通的。
我想我需要在我的第一个示例中使用 html = structure({ Id: data });
行来表示 Id: data
和 Date: data
但显然它们不能同时使用相同的 data
.
如何访问上一列的 date
数据并将其(与 routeSectionStepId
一起)传递到我的 _.template?
解决了
html = structure({ Id: data, Date: row.date });
和
<% if (Date == null){ %>