简体   繁体   English

如何从特定选定行的事件发送者数据中获取模型数据?

[英]How can I get the model data from my event sender data for specific selected row?

In my kendo grid, I have this Event attached: 在我的剑道网格中,我附加了以下事件:

.Events(events => events.DataBound("Planning.reSelectMeasurements('#=Label#')"))

From kendo grid: 从剑道网格:

 @(Html.Kendo().Grid<PlanningViewParam>().Name("Planning")
      .ClientRowTemplate(
     // INSERT HTML AND JS HERE
      )
      .DataSource(datasource => datasource.Ajax().Batch(false)
          .ServerOperation(false)
          .Read(read => read.Action("ReadMeasurements", "Planning", new { viewType = "A" }))
          .Model(model =>
          {
              model.Id(p => p.Order);
              model.Field(p => p.Label).Editable(false);
              model.Field(p => p.Color).Editable(false);
          })).Pageable(p=>p.Enabled(false))
              .HtmlAttributes(new { style = "height:202px; width:225px;",@class = "light-list-box"})
              .Scrollable(scrollable => scrollable.Height(100).Virtual(false))
         .Selectable(selectable => selectable
            .Mode(GridSelectionMode.Single)
            .Type(GridSelectionType.Row))
         .Events(events => events.DataBound("Planning.reSelectMeasurements('#=Label#')"))

Is it possible to pass information from my view model to this function instead of the literal string return? 是否可以将信息从我的视图模型传递给此函数,而不是传递文字字符串返回值? I noticed when I ran firebug and I put a breakpoint next to the function, it says label gets passed in as "#=Label#". 我注意到当我运行Firebug时,我在函数旁边放置了一个断点,它说标签以“#= Label#”的形式传入。

Where: 哪里:

reSelectMeasurements: function (label) {
            if (label == "Point") {
                Planning.reSelectPoint("A");
            }
            else if (label == "Angle") {
                Planning.reSelectAngle("A");
            }
        }

EDIT: 编辑:

Latest attempt: 最新尝试:

 if (events.sender._data.PointLabel == "Point") {
                Planning.reSelectPoint("A");
            }
            else if (events.sender._data.Label == "Angle") {
                Planning.reSelectAngle("A");
            }

when I get to _data. 当我到达_data时。 on debugging, it contains an array of data. 在调试时,它包含一个数据数组。 How do I pass in the specific row I selected in so that I can pass in the proper Label data? 如何传递所选的特定行,以便传递正确的Label数据?

so the hierarchy looks something like events.sender._data.[0].Label ? 所以层次结构看起来像events.sender._data.[0].Label吗?

I think this depends upon the version of the controls, but in 2014.2.903.545 this is how i pass data from the grid to a javascript function. 我认为这取决于控件的版本,但是在2014.2.903.545中,这就是将数据从网格传递到javascript函数的方式。

in razor: ... 在剃刀中:...

 .Events(e =>
               {
               e.Edit("readonlyifyKey");
               e.DataBound("bindMigrateButton");
               })

... ...

Then the function looks like this: 然后该函数如下所示:

 function bindMigrateButton(e) {

    var prjId = e.sender.element.context.id;
    prjId = prjId.replace('projects-setttings_', '');
    $('#import-config-btn__' + prjId).click(showImportWindow);

}

prjId holds the model id of my object im binding to the grid, so you should be able to access any property of your model in this fashion. prjId保存绑定到网格的我的对象的模型ID,因此您应该能够以这种方式访问​​模型的任何属性。

It looks like var prjId = e.sender.element.context.id; 看起来像var prjId = e.sender.element.context.id; is actually getting the dom element id, but you should still be able to access all the model elements off of e.sender , not exactly sure how its nested from there but the sender should have the model attributes. 实际上正在获取dom元素ID,但是您仍然应该能够访问e.sender之外的所有模型元素,不能完全确定e.sender是如何从那里嵌套的,但是发送者应该具有model属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM