[CLOSED] Uncaught TypeError: Cannot read property 'data' of undefined

  1. #1

    [CLOSED] Uncaught TypeError: Cannot read property 'data' of undefined

    i add a directevent in code behind.
     Store = 
                { 
                    new Store 
                    { 
                        Model = {
                            new Model {
                                IDProperty = "vouchId",
                                Fields = 
                                {
                                    new ModelField("vouchId"),
                                    new ModelField("pzzh") 
                                }
                            }
                        },
                        DataSource = data1
                    }
                }
    ...
                grid.DirectEvents.CellClick.Event += DirectEventHandler_CellClick;
                grid.DirectEvents.CellClick.ExtraParams.Add(new Ext.Net.Parameter { Name = "vouchId", Value = "this.record.data.vouchId",Mode = ParameterMode.Raw});
            public void DirectEventHandler_CellClick(object sender, DirectEventArgs e)
            {
                var vouchId = e.ExtraParams["vouchId"];
                X.Msg.Alert(vouchId,vouchId).Show(); 
            }
    error on the front :
    Uncaught TypeError: Cannot read property 'data' of undefined


    the whole code is
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Ext.Net;
    using TobrosCWTAccess;
    using TobrosCWTEf;
    using TobrosTools;
    
    namespace TobrosCWT.pages.cashflow
    {
        public partial class cashflow_data_adjust2 : System.Web.UI.Page
        {
            AccVouchMainService accVouchMainService = new AccVouchMainService();
            AccVouchSubService accVouchSubService = new AccVouchSubService();
            protected void Page_Load(object sender, EventArgs e)
            {
                if (!Ext.Net.X.IsAjaxRequest)
                {
    
                }
            }
            protected void LoadData(object sender, StoreReadDataEventArgs e)
            {
                int start = e.Start;
                int limit = e.Limit;
                int total = 0;
                var l = accVouchMainService.PageDdate(start, limit, out total);
                var data = l.Select(s => new { Ddate = s.ToString().Substring(0, 10) });
                //   var pagingList = new Paging<System.DateTime>(data, total);
                e.Total = total;
                s_AccVouchMain.DataSource = data;
                s_AccVouchMain.DataBind();
            }
            [DirectMethod]
            public string GetGrid2(Dictionary<string, string> parameters)
            {
                return "";
            }
            [DirectMethod]
            public string GetGrid1(Dictionary<string, string> parameters)
            {
                string vouchId = parameters["vouchId"];
                //根据vouchId查Cwzz_AccVouchSub
                var accVouchSubList = accVouchSubService.GetByVouchId1(int.Parse(vouchId));
    
                var m = new Model { IDProperty = "SerialID" };
                m.Fields.Add(new ModelField { Name = "SerialID" });
                m.Fields.Add(new ModelField { Name = "VouchId" });
                m.Fields.Add(new ModelField { Name = "Digest" });
                m.Fields.Add(new ModelField { Name = "Ccode" });
                m.Fields.Add(new ModelField { Name = "Cname", Type = ModelFieldType.Object, ServerMapping = "Cwzz_AccCode.CClass" });
                m.Fields.Add(new ModelField { Name = "Jfje" });
                m.Fields.Add(new ModelField { Name = "Dfje" });
                m.Fields.Add(new ModelField { Name = "Bill", Type = ModelFieldType.Object, ServerMapping = "Cwzz_AccVouchMain.Bill" });
                m.Fields.Add(new ModelField { Name = "Checker", Type = ModelFieldType.Object, ServerMapping = "Cwzz_AccVouchMain.Checker" });
                m.Fields.Add(new ModelField { Name = "Book", Type = ModelFieldType.Object, ServerMapping = "Cwzz_AccVouchMain.Book" });
                m.Fields.Add(new ModelField { Name = "VouchSource", Type = ModelFieldType.Object, ServerMapping = "Cwzz_AccVouchMain.VouchSource" });
                var store = new Store { DataSource = accVouchSubList };
                store.Model.Add(m);
                store.DataBind();
                var grid = new GridPanel();
                grid.ColumnModel.Add(new SummaryColumn { DataIndex = "Digest", Text = "摘要", Flex = 1, SummaryType = SummaryType.None, SummaryRenderer = { Handler = "return '合计:';" } });
                grid.ColumnModel.Add(new Column { DataIndex = "Ccode", Text = "科目编码" });
                grid.ColumnModel.Add(new Column { DataIndex = "Cname", Text = "科目名称" });
                grid.ColumnModel.Add(new SummaryColumn { DataIndex = "Jfje", Text = "借方金额", SummaryType = SummaryType.Sum });
                grid.ColumnModel.Add(new SummaryColumn { DataIndex = "Dfje", Text = "贷方金额", SummaryType = SummaryType.Sum });
                grid.ColumnModel.Add(new Column { DataIndex = "Bill", Text = "制单" });
                grid.ColumnModel.Add(new Column { DataIndex = "Checker", Text = "审核" });
                grid.ColumnModel.Add(new Column { DataIndex = "Book", Text = "记账" });
                grid.ColumnModel.Add(new Column { DataIndex = "VouchSource", Text = "凭证来源" });
                grid.Store.Add(store);
                var re = new RowExpander
                    {
                        Loader = new ComponentLoader
                            {
                                Mode = LoadMode.Component,
                                DirectMethod = "#{DirectMethods}.GetGrid2"
                            }
                    };
                var s = new Ext.Net.Summary { ID = "Summary1" };
                //grid.Plugins.Add(re);
                grid.Features.Add(s);
                grid.Listeners.ViewReady.Handler = "this.up('gridpanel').doLayout();";
                return ComponentLoader.ToConfig(grid);
    
            }
            [DirectMethod]
            public string GetGrid(Dictionary<string, string> parameters)
            {
                string date = parameters["date"];
                var ll = accVouchMainService.GetByDdate(date);
                var data1 = ll.Select(v => new { vouchId = v.VouchId, pzzh = v.VouchClassCode.Trim() + "-" + StringHelper.CompStr(v.VouchNo.ToString(), "0", 4) });
                var grid = new GridPanel
                {
                    Store = 
                { 
                    new Store 
                    { 
                        Model = {
                            new Model {
                                IDProperty = "vouchId",
                                Fields = 
                                {
                                    new ModelField("vouchId"),
                                    new ModelField("pzzh") 
                                }
                            }
                        },
                        DataSource = data1
                    }
                },
                    ColumnModel =
                    {
                        Columns = 
                        { 
                            new Column { Text = "凭证字号", DataIndex = "pzzh",Flex = 1}
                        }
                    },
                    Plugins =
                        {
                            new RowExpander
                                {
                                    Loader = new ComponentLoader
                                        {
                                            Mode  = LoadMode.Component,
                                            DirectMethod = "#{DirectMethods}.GetGrid1" ,
                                              LoadMask=
                                                {
                                                    ShowMask = true
                                                },
                                                 Params=
                                                 {
                                                     new Ext.Net.Parameter
                                                         {
                                                             Name = "vouchId",   
                                                             Value = "this.record.data.vouchId",
                                                             Mode = ParameterMode.Raw
                                                         }
                                                 }
                                        } 
                                }
                        }
                };
                grid.SelectionModel.Add(new RowSelectionModel { ID = "RowSelectionModel1" });
                grid.DirectEvents.CellClick.Event += DirectEventHandler_CellClick;
                grid.DirectEvents.CellClick.ExtraParams.Add(new Ext.Net.Parameter { Name = "vouchId", Value = "this.record.data.vouchId",Mode = ParameterMode.Raw});
                return ComponentLoader.ToConfig(grid);
            }
            public void DirectEventHandler_CellClick(object sender, DirectEventArgs e)
            {
                var vouchId = e.ExtraParams["vouchId"];
                X.Msg.Alert(vouchId,vouchId).Show(); 
            }
        }
    }
    Last edited by Daniil; Nov 05, 2013 at 8:34 AM. Reason: [CLOSED]
  2. #2
    Hi @tobros,

    Please clarify what do you mean by this?
    this.record.data.vouchId
    "this" is a GridPanel instance in its CellClick listener. It has no the "record" property.

    You should use the "record" argument.
    record.data.vouchId
  3. #3
    Quote Originally Posted by Daniil View Post
    Hi @tobros,

    Please clarify what do you mean by this?
    this.record.data.vouchId
    "this" is a GridPanel instance in its CellClick listener. It has no the "record" property.

    You should use the "record" argument.
    record.data.vouchId
    i change to this
     grid.DirectEvents.CellClick.ExtraParams.Add(new Ext.Net.Parameter { Name = "vouchId", Value = "record.data.vouchId",Mode = ParameterMode.Raw});
    error:
    Click image for larger version. 

Name:	QQ截图20131030142742.jpg 
Views:	10 
Size:	77.1 KB 
ID:	7143
  4. #4
    I guess you render that GridPanel dynamically and doesn't recreate during that DirectEvent.

    Any DirectEvent requires a control instance on server. In your case you see the ID (in the exception's message) of the GridPanel.

    You can switch to a DirectMethod. It doesn't require a control instance.
  5. #5
    Quote Originally Posted by Daniil View Post
    I guess you render that GridPanel dynamically and doesn't recreate during that DirectEvent.

    Any DirectEvent requires a control instance on server. In your case you see the ID (in the exception's message) of the GridPanel.

    You can switch to a DirectMethod. It doesn't require a control instance.
    <script type="text/javascript">
            var handleEdit = function (item, td, cellIndex, record, tr, rowIndex, e) {
                alert(record.data.vouchId);
            }
        </script>
                grid.SelectionModel.Add(new RowSelectionModel { ID = "RowSelectionModel1" });  
                grid.Listeners.CellClick.Handler = "handleEdit";
    i change to this , but handleEdit not execute , maybe because the cell is expandable?
  6. #6
    This should work:
    grid.Listeners.CellClick.Fn= "handleEdit";
    The difference between Fn and Handler is explained here:
    http://www.ext.net/2012/12/19/introd...xt-net-events/

Similar Threads

  1. Uncaught TypeError: Cannot read property 'items' of null
    By FlavioSilveira in forum 2.x Help
    Replies: 6
    Last Post: Sep 20, 2013, 7:37 PM
  2. Replies: 1
    Last Post: Jun 05, 2013, 11:01 AM
  3. Replies: 4
    Last Post: May 30, 2013, 1:36 PM
  4. Replies: 2
    Last Post: Apr 10, 2012, 12:08 PM
  5. [CLOSED] Uncaught TypeError: Object #<Object> has no method '***'
    By Sevilay Tanış in forum 1.x Legacy Premium Help
    Replies: 7
    Last Post: Mar 27, 2012, 4:44 PM

Posting Permissions