2016-10-03 6 views
0

私は、カスタムドロップダウンリストフィルタ(データソースからその列の一意の値を選択する)を持つデータ列を持つ剣道グリッドを持っています。可読性のために宣言的な剣道初期化からjs関数を抽出するには?

これはうまく動作しませんが、私はfunction(options) {...}をhtmlから抽出したいと思います。ビジュアルスタジオ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> 

答えて

1

次の標準的なアプローチを使用します

{ 
    "field": "location_name", 
    "title": "Location", 
    "filterable": { 
     cell: { 
      template: myFunction, 
      showOperators: false 
     } 
    } 
} 

をそしてどこかmyFunctionを定義します。

<script> 

    function myFunction(args) { 
     //args.element... 
    } 

</script> 
関連する問題