1

我尝试使用 Javascript 从 Ext.net 中的 GridPanel 获取值,我使用 Hanlder 在 Javascript 函数中调用 gaSelectBind() 但它返回 [object NodeList]。

<script type="text/javascript">
    var nodelist;
    nodelist = document.getElementsByName('grid-device-name')
    function gaSelectBind() {
        App.ga_device_name.setValue(nodelist);
    };
</script>

这是我的数据对象:

DateTime now = DateTime.Now;
    var dataDevice = new object[]
            {
                new object[] {null, false , "35 RUTA", now, null , null },
                new object[] {null, false , "770SBW", now, null , null },
                new object[] {null, false , "CORSA", now, null , null },
                new object[] {null, false , "icon2010", now, null , null },
                new object[] {null, false , "MouGL", now, null , null },
                new object[] {null, false , "mt90", now, null , null },
                new object[] {null, false , "MT90-Renny", now, null , null },
                new object[] {null, false , "MVT600-Fuel1111", now, null , null }
            };

我使用文本字段来设置值

itemchildpan1.Add(Html.X().TextField().FieldLabel("Device Name").ID("ga_device_name"));

我的网格面板:

.GridPanel().Title("Device")
.Store(store =>
{//Load store from Data Object----
    store.Add(Html.X().Store().ID("Storer1")
                    .AutoLoad(true)
                    .Model(model => model.Add(Html.X().Model()
                        .Fields(fields =>
                        {
                            fields.Add(Html.X().ModelField().Name("grid-alarm"));
                            fields.Add(Html.X().ModelField().Name("grid-check"));
                            fields.Add(Html.X().ModelField().Name("grid-device-name"));
                            fields.Add(Html.X().ModelField().Name("grid-lastupdate"));
                            fields.Add(Html.X().ModelField().Name("grid-status"));
                            fields.Add(Html.X().ModelField().Name("grid-retry"));
                        }
                        )))
                    .DataSource(dataDevice)
                    );
})

.ColumnModel(columnModel =>
{//Add Data Object from store to Column
    columnModel.Columns.Add(Html.X().Column().Text("").DataIndex("grid-alarm").Width(30));
    columnModel.Columns.Add(Html.X().CheckColumn().TdCls("td-non-img-checkcolum").DataIndex("grid-check").Width(30).Editable(true));
    columnModel.Columns.Add(Html.X().Column().Text("Devide Name").DataIndex("grid-device-name"));
    columnModel.Columns.Add(Html.X().Column().Text("Latest Update").DataIndex("grid-lastupdate").Width(120));
    columnModel.Columns.Add(Html.X().Column().Text("Status").DataIndex("grid-status"));
    columnModel.Columns.Add(Html.X().Column().Text("Retry").DataIndex("grid-retry"));
})
.SelectionModel(gaSelectModel =>
{//Listener Event Handler use to call "gaSelectBind()" Function
    gaSelectModel.Add(Html.X().RowSelectionModel().Listeners(garowSelectListen =>
    {
        garowSelectListen.Select.Handler = "gaSelectBind();";
    }));
})

我无法从网格中获取价值,它显示

[object NodeList]
4

1 回答 1

0

您需要进行两项更改:

  1. 替换以下行:

    // Old
    garowSelectListen.Select.Handler = "gaSelectBind();";
    
    // New
    garowSelectListen.Select.Fn = "gaSelectBind";
    
  2. 将您的替换<script>为以下内容:

    <script type="text/javascript">
        var gaSelectBind = function (item, record, index) {
            App.ga_device_name.setValue(record.data.grid-device-name);
        };
    </script>
    

可以从您的示例中删除以下代码,因为它不起作用:

// Remove this code...
var nodelist;
nodelist = document.getElementsByName('grid-device-name')

希望这可以帮助。

于 2012-10-23T15:19:50.890 回答