【问题标题】:EXT-NET: Uncaught TypeError: Cannot read property 'type' of nullEXT-NET:未捕获的 TypeError:无法读取 null 的属性“类型”
【发布时间】:2017-12-21 10:42:36
【问题描述】:

我正在尝试实现这个例子: Dynamic_GridPanels

但是当我点击展开外部网格时,我收到了这个错误:

未捕获的类型错误:无法读取 null 的属性“类型”

通过使用断点,我发现从 DirectMethod 返回后发生错误。我没有发布外部网格 (misArtStore) 的代码,因为它工作正常。

这是我的代码:

标记

<ext:GridPanel
                                    runat="server"
                                    Title="Expander Rows with GridPanel"
                                    Collapsible="true"
                                    AnimCollapse="true"
                                    Icon="Table"
                                    Width="600"
                                    Height="450"
                                    DisableSelection="true">
                                    <Store>
                                        <ext:Store ID="misArtStore" runat="server">
                                            <Model>
                                                <ext:Model runat="server" IDProperty="Id">
                                                    <Fields>
                                                        <ext:ModelField Name="Id" />
                                                        <ext:ModelField Name="missing" />
                                                    </Fields>
                                                </ext:Model>
                                            </Model>
                                        </ext:Store>
                                    </Store>
                                    <ColumnModel runat="server">
                                        <Columns>
                                            <ext:Column runat="server" Text="Artifacts" DataIndex="missing" Flex="1" Hideable="false" />
                                        </Columns>
                                    </ColumnModel>
                                    <Plugins>
                                        <ext:RowExpander runat="server">
                                            <Loader runat="server" DirectMethod="#{DirectMethods}.GetGrid" Mode="Component">
                                                <LoadMask ShowMask="true" />
                                                <Params>
                                                    <ext:Parameter Name="id" Value="this.record.getId()" Mode="Raw" />
                                                </Params>
                                            </Loader>
                                        </ext:RowExpander>
                                    </Plugins>
                                </ext:GridPanel>

代码背后

[DirectMethod]
        public string GetGrid(Dictionary<string, string> parameters)
        {
            string id = parameters["id"];
            DALP.PDBDataContext dc = new DALP.PDBDataContext();
            DAL.AdminDataContext ds = new DAL.AdminDataContext();

            string uname = HttpContext.Current.User.Identity.Name;

            var clientid = (from u in ds.ClientUsers            
                            where u.UserName == uname
                            select u.ClientId);

            var sites = (from mc in dc.TMFCategories //sites is populated correctly
                        join mat in dc.TMFTemplateCts on mc.Id equals mat.Catid
                        join st in dc.Sites on mat.ctid equals st.CTid
                        where ( (!dc.TMFFiles.Any(x=>x.SiteId==st.Siteid)) && mat.Required == true && mat.Clientid == int.Parse(clientid.First().ToString()) && mat.ctid == ctid && mc.Id == Convert.ToInt32(id)) 
                        select new { Siteid = st.Siteid, Site = st.FullName });
            

            GridPanel grid = new GridPanel
            {
                Height = 200,
                EnableColumnHide = false,
                Store =
            {
                new Store
                {
                    Model = {
                        new Model {
                            IDProperty = "Siteid",
                            Fields =
                            {
                                new ModelField("Siteid"),
                                new ModelField("Site")
                            }
                        }
                    },
                    DataSource = sites
                }
            },
                ColumnModel =
                {
                    Columns =
                {
                    new Column { Text = "Site", DataIndex = "Site", Width = 150 }
                }
                }
            };

            return ComponentLoader.ToConfig(grid);
        }

Chrome 控制台:

未捕获的类型错误:无法读取 null 的属性“类型”

at F.setLayout (ext.axd:19)
at F.getLayout (ext.axd:19)
at F.add (ext.axd:19)
at g.Ext.ComponentLoader.Renderer.Component (ext.axd:445)
at g.onComplete (ext.axd:495)
at Object.complete (ext.axd:463)
at Object.userSuccess (ext.axd:268)
at F.executeScriptDelay (ext.axd:256)
at F.executeScript (ext.axd:255)
at F.requestSuccessHandler (ext.axd:248)

编辑

(使用@Przemek提供的解决方案解决了图像错误)

【问题讨论】:

    标签: javascript c# extjs grid ext.net


    【解决方案1】:

    这是 linq 查询的问题,而不是 Grid。尝试使用:

    DataSource = sites.ToList()
    

    或创建您自己的自定义对象列表:

    public class CustomObject
    {
        public string Siteid {get; set; }
        public string Site {get; set; }
    }
    
    (...)
    
    select new CustomObject() { Siteid = st.Siteid, Site = st.FullName });
    

    编辑

    没有数据库连接的工作示例:

    *.aspx:

    <ext:GridPanel runat="server" Title="Expander Rows with GridPanel"
        Collapsible="true" AnimCollapse="true" Icon="Table"
        Width="600" Height="450" DisableSelection="true">
        <Store>
            <ext:Store ID="misArtStore" runat="server">
                <Model>
                    <ext:Model runat="server" IDProperty="Id">
                        <Fields>
                            <ext:ModelField Name="Id" />
                            <ext:ModelField Name="missing" />
                        </Fields>
                    </ext:Model>
                </Model>
            </ext:Store>
        </Store>
        <ColumnModel runat="server">
            <Columns>
                <ext:Column runat="server" Text="Artifacts" DataIndex="missing" 
                    Flex="1" Hideable="false" />
            </Columns>
        </ColumnModel>
        <Plugins>
            <ext:RowExpander runat="server">
                <Loader runat="server" DirectMethod="#{DirectMethods}.GetGrid" Mode="Component">
                    <LoadMask ShowMask="true" />
                    <Params>
                        <ext:Parameter Name="id" Value="this.record.getId()" Mode="Raw" />
                    </Params>
                </Loader>
            </ext:RowExpander>
        </Plugins>
    </ext:GridPanel>
    

    *.aspx.cs:

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Page.IsPostBack || X.IsAjaxRequest)
            return;
    
        misArtStore.DataSource = new object[] 
        { 
            new { Id = "1", missing = "missing 1" },
            new { Id = "2", missing = "missing 2" },
            new { Id = "3", missing = "missing 3" }
        };
    
        misArtStore.DataBind();
    }
    
    [DirectMethod]
    public string GetGrid(Dictionary<string, string> parameters)
    {
        GridPanel grid = new GridPanel
        {
            Height = 200,
            EnableColumnHide = false,
            Store =
            {
                new Store
                {
                    Model = 
                    {
                        new Model 
                        {
                            IDProperty = "Siteid",
                            Fields = { new ModelField("Siteid"), new ModelField("Site") }
                        }
                    },
                    DataSource = new object[] 
                    { 
                        new { Siteid = "1", Site = "Site 1" },
                        new { Siteid = "2", Site = "Site 2" }
                    }
                }
            },
            ColumnModel =
            {
                Columns = { new Column { Text = "Site", DataIndex = "Site", Width = 150 } }
            }
        };
    
        return ComponentLoader.ToConfig(grid);
    }
    

    【讨论】:

    • 谢谢!我解决了图像中的错误,但我仍然收到 javascript 错误 Uncaught TypeError: Cannot read property 'type' of null
    • 我相信这个property 'type' of null 与您的网格问题无关。我在第一个答案中添加了可行的解决方案。
    • 但是为什么当我尝试扩展行扩展器时它会显示?我尝试了你的解决方案,仍然是同样的错误。所以可能与datasource 无关
    • 我的解决方案在我的环境中的控制台中没有任何错误。我可以建议创建一个全新的项目,除了 ext.net 之外没有任何外部框架,然后尝试一下。
    • 那是真的......也在这里工作。但是为什么在我的项目中不起作用?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-06-25
    • 2022-11-20
    • 2022-11-24
    • 2022-12-20
    • 1970-01-01
    • 1970-01-01
    • 2017-07-15
    相关资源
    最近更新 更多