0
我有一個kendo網格,數據列有一個自定義的dropdownlist過濾器(從數據源中選擇該列的唯一值)。如何從declaritive kendo ui初始化中提取js函數以提高可讀性?
它的工作原理,但我想從HTML中提取function(options) {...}
,因爲它是非常不可讀的,Visual Studio 2015不會將代碼解釋爲JavaScript。
<div id="PatrolDurationRecords">
<div data-filterable='{ "mode": "row" }'
data-role='grid'
data-sortable='true'
data-bind='source: reportData.PatrolDurations, events: {excelExport: excelExportHandler}'
data-pageable='{ "pageSize": 10 }'
data-toolbar='["excel"]'
data-excel='{ "fileName": "PatrolDurations.xlsx", "allPages": "true" }'
data-columns='[
{
"field": "patrol_id_plain",
"title": "Patrol ID",
"filterable": false
},
{
"field": "location_name",
"title": "Location",
"filterable": {
cell: {
template: function (args) {
args.element.kendoDropDownList({
dataTextField: "optionText",
dataValueField: "optionValue",
valuePrimitive: true,
dataSource: {
transport: {
read:
function(options) { //<-- I want to extract this function outside of this html declaration
console.log("viewModel.reportData.PatrolDurations = ");
console.log(viewModel.reportData.PatrolDurations);
var len = viewModel.reportData.PatrolDurations.length;
var locationName;
var setObj = {};
for(var i = 0; i < len; i++)
{
locationName = viewModel.reportData.PatrolDurations[i].location_name;
setObj[locationName] = "";//not concerned with object value, we use setObj as a Set where the keys are the set values
}
var ddlOptions = [];
for(var e in setObj)
{
ddlOptions.push({
"optionText": e,
"optionValue": e
});
}
console.log("ddlOptions = ");
console.log(ddlOptions);
options.success(ddlOptions);
}
}
}
});
},
showOperators: false
}
}
},
{
"field": "company_name",
"title": "Company",
"filterable": { "cell": { "operator": "contains"}}
},
{
"field": "patrol_start",
"title": "Start",
"filterable": false
},
{
"field": "patrol_end",
"title": "End",
"filterable": false
},
{
"field": "patrol_user",
"title": "Patrolled By",
"filterable": { "cell": { "operator": "contains"}}
},
{
"field": "duration",
"title": "Duration",
"template": kendo.template($("#durationTemplate").html()),
"filterable": false
},
{
"title": "",
"template": kendo.template($("#viewLinkTemplate").html()),
"filterable": false
}
]'>
</div>
</div>