从gridOptions获取selectedKeyNames

时间:2019-01-11 19:52:04

标签: javascript angularjs kendo-grid dom-events

我正在尝试获取网格的选定行并将其分配给变量。在Kendo的演示中,选定的行将输出到控制台:

[{"end": 1547230999000, "attributes": {}, "metric": "system.cpu.idle", "interval": 20, "start": 1547227400000, "length": 180, "query_index": 0, "aggr": null, "scope": "host:osboxes", "pointlist": [[1547227400000.0, 99.6485366821289], [1547227420000.0, 99.60060119628906], [1547227440000.0, 99.40513610839844], [1547227460000.0, 99.5660171508789], [1547227480000.0, 99.68238067626953], [1547227500000.0, 99.58213806152344], [1547227520000.0, 99.56404876708984], [1547227540000.0, 99.59886169433594], [1547227560000.0, 99.33905792236328], [1547227580000.0, 99.49874877929688], [1547227600000.0, 99.69874572753906], [1547227620000.0, 99.58246231079102], [1547227640000.0, 99.01371002197266], [1547227660000.0, 99.53114318847656], [1547227680000.0, 99.48202896118164], [1547227700000.0, 99.49647521972656], [1547227720000.0, 99.68254089355469], [1547227740000.0, 99.43094635009766], [1547227760000.0, 99.38209533691406], [1547227780000.0, 99.6488265991211], [1547227800000.0, 99.42307662963867], [1547227820000.0, 99.28117370605469], [1547227840000.0, 99.51512908935547], [1547227860000.0, 96.35371780395508], [1547227880000.0, 99.0471420288086], [1547227900000.0, 99.59866333007812], [1547227920000.0, 99.41494750976562], [1547227940000.0, 99.4984130859375], [1547227960000.0, 99.5489501953125], [1547227980000.0, 99.48962783813477], [1547228000000.0, 99.58173370361328], [1547228020000.0, 99.63229370117188], [1547228040000.0, 99.38098907470703], [1547228060000.0, 99.46452331542969], [1547228080000.0, 99.5501480102539], [1547228100000.0, 99.46395111083984], [1547228120000.0, 99.6651611328125], [1547228140000.0, 99.66544342041016], [1547228160000.0, 99.5067024230957], [1547228180000.0, 99.53192901611328], [1547228200000.0, 99.58263397216797], [1547228220000.0, 99.4233169555664], [1547228240000.0, 99.51488494873047], [1547228260000.0, 99.69884490966797], [1547228280000.0, 99.17123413085938], [1547228300000.0, 99.48178100585938], [1547228320000.0, 99.61544799804688], [1547228340000.0, 99.38138961791992], [1547228360000.0, 99.49983215332031], [1547228380000.0, 99.58074951171875], [1547228400000.0, 99.44026565551758], [1547228420000.0, 99.56558227539062], [1547228440000.0, 99.61634826660156], [1547228460000.0, 99.2971076965332], [1547228480000.0, 99.514404296875], [1547228500000.0, 99.56529235839844], [1547228520000.0, 99.48181915283203], [1547228540000.0, 99.49799346923828], [1547228560000.0, 99.56507110595703], [1547228580000.0, 99.47320556640625], [1547228600000.0, 99.49816131591797], [1547228620000.0, 99.59886169433594], [1547228640000.0, 99.0047836303711], [1547228660000.0, 99.48117065429688], [1547228680000.0, 99.66544342041016], [1547228700000.0, 99.49843215942383], [1547228720000.0, 99.48194885253906], [1547228740000.0, 99.63235473632812], [1547228760000.0, 99.36409378051758], [1547228780000.0, 93.1688461303711], [1547228800000.0, 99.34782409667969], [1547228820000.0, 99.46506118774414], [1547228840000.0, 99.33065795898438], [1547228860000.0, 99.59893035888672], [1547228880000.0, 99.47415924072266], [1547228900000.0, 99.46299743652344], [1547228920000.0, 99.5824966430664], [1547228940000.0, 99.39748764038086], [1547228960000.0, 99.46452331542969], [1547228980000.0, 99.71566772460938], [1547229000000.0, 99.4896354675293], [1547229020000.0, 99.481689453125], [1547229040000.0, 99.48186492919922], [1547229060000.0, 99.43965148925781], [1547229080000.0, 99.41500854492188], [1547229100000.0, 99.56536102294922], [1547229120000.0, 99.45612716674805], [1547229140000.0, 99.28033447265625], [1547229160000.0, 98.72547149658203], [1547229180000.0, 99.36448669433594], [1547229200000.0, 99.39749145507812], [1547229220000.0, 99.55000305175781], [1547229240000.0, 99.32996368408203], [1547229260000.0, 99.43115234375], [1547229280000.0, 99.41422271728516], [1547229300000.0, 99.41427993774414], [1547229320000.0, 99.4978256225586], [1547229340000.0, 99.63327026367188], [1547229360000.0, 99.45573425292969], [1547229380000.0, 99.04618835449219], [1547229400000.0, 99.56463623046875], [1547229420000.0, 99.42306137084961], [1547229440000.0, 99.36380004882812], [1547229460000.0, 99.6164779663086], [1547229480000.0, 99.48064422607422], [1547229500000.0, 99.44741821289062], [1547229520000.0, 99.5820083618164], [1547229540000.0, 99.23918914794922], [1547229560000.0, 99.38034057617188], [1547229580000.0, 99.58187103271484], [1547229600000.0, 99.47303771972656], [1547229620000.0, 99.44770050048828], [1547229640000.0, 99.56521606445312], [1547229660000.0, 99.36420822143555], [1547229680000.0, 93.31424713134766], [1547229700000.0, 99.19745635986328], [1547229720000.0, 99.3642807006836], [1547229740000.0, 99.3148422241211], [1547229760000.0, 99.41403198242188], [1547229780000.0, 98.98696899414062], [1547229800000.0, 99.36422729492188], [1547229820000.0, 99.59711456298828], [1547229840000.0, 99.41479110717773], [1547229860000.0, 99.4476089477539], [1547229880000.0, 99.59845733642578], [1547229900000.0, 99.42321014404297], [1547229920000.0, 99.46488189697266], [1547229940000.0, 99.59845733642578], [1547229960000.0, 99.51408767700195], [1547229980000.0, 99.53137969970703], [1547230000000.0, 99.59893035888672], "expression": "system.cpu.idle{host:osboxes}", "unit": [{"family": "percentage", "scale_factor": 1.0, "name": "percent", "short_name": "%", "plural": "percent", "id": 17}, null], "display_name": "system.cpu.idle"}], "to_date": 1547231000000, "resp_version": 1, "query": "system.cpu.idle{*}by{host}", "message": "", "group_by": ["host"]}

这正是我需要的,除了我想将更改事件中的选定行分配给变量。

  <!DOCTYPE html>
    <html>
    <head>
        <meta charset="utf-8"/>
        <title>Kendo UI Snippet</title>

        <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2018.3.1017/styles/kendo.common.min.css"/>
        <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2018.3.1017/styles/kendo.rtl.min.css"/>
        <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2018.3.1017/styles/kendo.silver.min.css"/>
        <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2018.3.1017/styles/kendo.mobile.all.min.css"/>

        <script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
        <script src="https://kendo.cdn.telerik.com/2018.3.1017/js/kendo.all.min.js"></script>
    </head>
    <body>

    <div id="grid"></div>
    <script>
    $("#grid").kendoGrid({
      columns: [
        { field: "name" },
        { field: "age" }
      ],
      dataSource: {
        data: [
          { id: 1, name: "Jane Doe", age: 30 },
          { id: 2, name: "John Doe", age: 33},
          { id: 3, name: "Jim Doe", age: 30 },
          { id: 4, name: "Jack Doe", age: 33}
        ],
        schema: {
          model: { id: "id" }
        }
      },
      change: function(e) {
        console.log(this.selectedKeyNames());
      },
      selectable: "multiple, row",
      persistSelection: true
    });
    </script>
    </body>
    </html>

我已经将'row'定义为var row;在控制器内(第一行位于页面顶部:

change: function (e) {
                        row = this.selectedKeyNames();
             `enter code here`       },

但是当我尝试发布数据时,我得到的行是“未定义”消息。

var app = angular.module('collection-app', ['kendo.directives'])
.controller('CollectionController', ['$scope', '$http', "$window",     function ($scope, $http, $window) {
    var self = this;
    var dataUrl = UrlParams.type != null ? UrlParams.Collection + "?type=" + UrlParams.type : UrlParams.Collection;
    var viewUrl = UrlParams.view != null ? UrlParams.Collection + "/Views/" + UrlParams.view : UrlParams.Collection + "/Views/Default";
    var row;

是因为无法在gridOptions中分配值吗?

0 个答案:

没有答案