简体   繁体   English

Blazor TypeError:无法在 Object.e [as removeLogicalChild] 处读取 null 的属性“removeChild”

[英]Blazor TypeError: Cannot read property 'removeChild' of null at Object.e [as removeLogicalChild]

I created a component for a dual list box.我为双列表框创建了一个组件。 Everything is fine but when I submit I get an error.一切都很好,但是当我提交时出现错误。

 <EditForm Model="Model.Report" class="kt-form" OnValidSubmit="Model.OnSearch">
                <div class="modal-header">
                    <h5 class="modal-title" id="exampleModalLabel">Edit Columns</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    </button>
                </div>
                <div class="modal-body">
                    <div class="row">
                        <div class="col-md-12">
                            <Project.Components.DualListbox ReportColumns="Model.Report.ReportColumns" Id="ReportColumns" @bind-Value="@Model.Report.ReportColumns"></Project.Components.DualListbox>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary btn-sm" @onclick="Model.OnCloseModal"><i class="la la-close"></i> Close</button>
                    <button type="submit" class="btn btn-primary btn-sm"><i class="la la-exchange"></i> Change</button>
                </div>
            </EditForm>

DualListbox Razor code : DualListbox Razor 代码

@typeparam TValue
@inherits InputBase<TValue>


@if (ReportColumns != null)
{
    <select id="@Id" class="kt-dual-listbox" multiple>

        @foreach (var column in ReportColumns.OrderBy(c => c.Sort))
        {
            if (column.IsChecked == 1)
            {
                <option value="@column.Id" selected>@column.Title</option>
            }
            else
            {
                <option value="@column.Id">@column.Title</option>
            }
        }
    </select>
}

* DualListbox code-behind *: * DualListbox代码隐藏 *:

using Project.Models;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Forms;
using Microsoft.JSInterop;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Threading.Tasks;

namespace Project.Components
{
    public partial class DualListbox<TValue> : InputBase<TValue>
    {
        [Parameter] public string Id { get; set; }
        [Inject] IJSRuntime JSRuntime { get; set; }
        [Parameter] public ICollection<ReportColumn> ReportColumns { get; set; }

        public DotNetObjectReference<DualListbox<TValue>> DotNetRef;
        [Parameter] public EventCallback<object> OnChanged { get; set; }
        protected override bool TryParseValueFromString(string value, out TValue result, out string validationErrorMessage)
        {
            try
            {
                if (value == "null")
                {
                    value = null;
                }
                if (typeof(TValue) == typeof(string))
                {
                    result = (TValue)(object)value;
                    validationErrorMessage = null;

                    return true;
                }
                else if (typeof(TValue) == typeof(int) || typeof(TValue) == typeof(int?))
                {
                    int.TryParse(value, NumberStyles.Integer, CultureInfo.InvariantCulture, out var parsedValue);
                    result = (TValue)(object)parsedValue;
                    validationErrorMessage = null;

                    return true;
                }

                throw new InvalidOperationException($"{GetType()} does not support the type '{typeof(TValue)}'.");
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        protected override void OnInitialized()
        {
            base.OnInitialized();
            DotNetRef = DotNetObjectReference.Create(this);
        }

        protected override async Task OnAfterRenderAsync(bool firstRender)
        {
            await base.OnAfterRenderAsync(firstRender);
            if (firstRender)
            {
                await JSRuntime.InvokeVoidAsync("dualListboxComponent.init", Id, DotNetRef, "Change_SelectWithFilterBase");
            }
        }

        [JSInvokable("Change_SelectWithFilterBase")]
        public void Change(string value)
        {
            try
            {
                if (value == "null")
                {
                    value = null;
                }

                var array = value.Split("#");
                if (array[0] == "add")
                {
                    int _value = int.Parse(array[1]);
                    var report = ReportColumns.Where(c => c.Id == _value).FirstOrDefault();
                    report.IsChecked = 1;
                }
                else
                {
                    int _value = int.Parse(array[1]);
                    var report = ReportColumns.Where(c => c.Id == _value).FirstOrDefault();
                    report.IsChecked = 0;
                } 

            }
            catch (Exception ex)
            {
                throw ex;
            }

            if (OnChanged.HasDelegate)
                OnChanged.InvokeAsync(value);
        }
    }
}

[2020-02-12T07:42:28.867Z] Error: There was an error applying batch 7. e.log @ blazor.server.js:15 blazor.server.js:8 Uncaught (in promise) [2020-02-12T07:42:28.867Z] 错误:应用批处理 7 时出错。e.log @ blazor.server.js:15 blazor.server.js:8 Uncaught (in promise)

TypeError: Cannot read property 'insertBefore' of null at Object.s [as insertLogicalChild] (blazor.server.js:8) at e.insertText (blazor.server.js:8) at e.insertFrame (blazor.server.js:8) at e.applyEdits (blazor.server.js:8) at e.updateComponent (blazor.server.js:8) at Object.t.renderBatch (blazor.server.js:1) at e.类型错误:无法在 Object.s [as insertLogicalChild] (blazor.server.js:8) at e.insertText (blazor.server.js:8) at e.insertFrame (blazor.server.js) 中读取 null 的属性“insertBefore” :8) 在 e.applyEdits (blazor.server.js:8) 在 e.updateComponent (blazor.server.js:8) 在 Object.t.renderBatch (blazor.server.js:1) 在 e. (blazor.server.js:15) at blazor.server.js:15 at Object.next (blazor.server.js:15) at blazor.server.js:15 blazor.server.js:15 [2020-02-12T07:42:28.926Z] Error: System.AggregateException: One or more errors occurred. (blazor.server.js:15) 在 blazor.server.js:15 在 Object.next (blazor.server.js:15) 在 blazor.server.js:15 blazor.server.js:15 [2020-02- 12T07:42:28.926Z] 错误:System.AggregateException:发生一个或多个错误。 (TypeError: Cannot read property 'insertBefore' of null) ---> System.InvalidOperationException: TypeError: Cannot read property 'insertBefore' of null at Microsoft.AspNetCore.Components.RenderTree.Renderer.InvokeRenderCompletedCallsAfterUpdateDisplayTask(Task updateDisplayTask, Int32[] updatedComponents) --- End of inner exception stack trace --- (TypeError: 无法读取 null 的属性“insertBefore”) ---> System.InvalidOperationException: TypeError: 无法读取 Microsoft.AspNetCore.Components.RenderTree.Renderer.InvokeRenderCompletedCallsAfterUpdateDisplayTask(Task updateDisplayTask, Int32[] updatedComponents 处的 null 属性“insertBefore” ) --- 内部异常堆栈跟踪结束---

So, this may not be your exact answer, but it may give a clue to someone who stumbles upon this SO question.因此,这可能不是您的确切答案,但它可能会为偶然发现此 SO 问题的人提供线索。 In my case, this was the result of swapping out a Font Awesome icon within button text as opposed to using two separate buttons.就我而言,这是在按钮文本中换出一个 Font Awesome 图标而不是使用两个单独的按钮的结果。

This may be related because you are using the JSRuntime in combination with "report.IsChecked = 1;"这可能是相关的,因为您将 JSRuntime 与“report.IsChecked = 1;”结合使用syntax, which I assume is changing UI element state client-side that Blazor Server is trying to (but unable) to track.语法,我假设它正在更改 Blazor 服务器试图(但无法)跟踪的 UI 元素状态客户端。

When I used conditional logic within a single button to swap out the icon, I received an error, "blazor TypeError: Cannot read property 'removeChild' of null".当我在单个按钮中使用条件逻辑来换出图标时,我收到一个错误,“blazor TypeError:无法读取 null 的属性‘removeChild’”。 This syntax using two separate buttons, however, worked just fine:但是,这种使用两个单独按钮的语法效果很好:

@if (AllowAllPartners)
{
    <button @onclick="(() => AllowAllPartnersToggle())">
        <i class="far fa-check-square"></i>
    </button>
}
else
{
    <button @onclick="(() => AllowAllPartnersToggle())">
        <i class="far fa-square"></i>
    </button>
}

My problem was in FontAwesome too.我的问题也出在 FontAwesome 中。 In my case, put icons inside <span></span> solved problems.就我而言,将图标放在<span></span>解决了问题。

   @if (conditional)
            {
                <span>
                    <i class="fas fa-check"></i>
                </span>
            }
            else
            {
                <span>
                    <i class="fas fa-times"></i>
                </span>
            }

In my case the same error was caused by my use of Bootstrap Dismissible Alerts, containing a MatBlazor component, and/or FontAwesome icon.在我的情况下,同样的错误是由我使用 Bootstrap Dismissible Alerts 引起的,其中包含一个 MatBlazor 组件和/或 FontAwesome 图标。

Placing the alert inside another <div></div> solved this issue.将警报放在另一个<div></div>解决了这个问题。 Placing the icon/component within the alert inside <span></span> did not work, but I found this solution thanks to Diego's suggestion :-)将图标/组件放在<span></span>内的警报内不起作用,但由于 Diego 的建议,我找到了这个解决方案 :-)

   <div>
      <div class="alert alert-warning alert-dismissible fade show" role="alert">
          Warning Text <MatTooltip Tooltip="Tooltip text" Context="_context1" Wrap="true" Position="@MatTooltipPosition.Top"><i class="far fa-question-circle"></i></MatTooltip>
          <button type="button" class="close" data-dismiss="alert" aria-label="Close">
             <span aria-hidden="true">&times;</span>
          </button>
       </div>
    </div>

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

相关问题 未捕获的TypeError:如果不使用removeChild,则无法读取null的属性“removeChild” - Uncaught TypeError: Cannot read property 'removeChild' of null without using removeChild Vue.js错误:未捕获的TypeError:无法读取null的属性&#39;removeChild&#39; - Vuejs error: Uncaught TypeError: Cannot read property 'removeChild' of null 无法读取null dropzone的属性&#39;removeChild&#39; - Cannot read property 'removeChild' of null dropzone 无法使用JSP读取null的属性“ removeChild” - Cannot read property 'removeChild' of null using JSP 无法读取jsni中null的属性removeChild - Cannot read property removeChild of null in jsni 未捕获的TypeError:无法读取null的属性“ removeChild”(使用来自Instagram的JSONP响应) - Uncaught TypeError: Cannot read property 'removeChild' of null (Using JSONP Response from Instagram) Object 类型错误:无法读取 null 的属性“标题” - Object TypeError: Cannot read property 'title' of null Javascript - 未捕获的类型错误:无法读取未定义的属性“removeChild” - Javascript - Uncaught TypeError: Cannot read property 'removeChild' of undefined …未捕获的TypeError:无法读取null的属性&#39;__e3_&#39; - …Uncaught TypeError: Cannot read property '__e3_' of null 未捕获的TypeError:无法读取null的属性&#39;__e3_&#39; - Uncaught TypeError: Cannot read property '__e3_' of null
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM