【问题标题】:Error: infinite rendering invalidation detected错误:检测到无限渲染失效
【发布时间】:2018-09-20 01:19:05
【问题描述】:

我有一个 Ember 应用,其版本如下:

DEBUG: Ember             : 3.0.0
DEBUG: Ember Data        : 3.0.2
DEBUG: jQuery            : 3.3.1
DEBUG: Ember Dialog      : 3.1.0
DEBUG: Ember Simple Auth : 1.6.0

我有一个将数据提取到模型中的路由,并且该数据被传递到组件中。每当我向这个组件添加一个关闭操作时,我都会得到一个

Error: infinite rendering invalidation detected

每当我删除关闭操作代码时,一切正常。

路线代码:

import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';

export default Route.extend({
  currentUser: service('current-user'),

  model() {
    return this.store.findAll('account');
  },

  actions:{
    saveNewCustomer() {

    }
  }
});

导致错误的模板:

<div class="panel panel-primary">
    <div class="panel-heading">
        <h2 class="panel-title">{{t 'account.modals.new_customer.title'}}</h2>
    </div>

    {{account/customers/filter-accounts
            accounts=model
            currentUser=currentUser
            customerAdded=(action "saveNewCustomer")}}

</div>

模板工作:

<div class="panel panel-primary">
    <div class="panel-heading">
        <h2 class="panel-title">{{t 'account.modals.new_customer.title'}}</h2>
    </div>

    {{account/customers/filter-accounts
            accounts=model
            currentUser=currentUser)}}

</div>

组件的代码在这里:

import Component from '@ember/component';

export default Component.extend({
  actions:{
    selectedAccount(account) {
      this.set('selectedAccount', account);
      this.toggleProperty('newCustomerModal');
    },

    toggleNewCustomerModal() {
      this.toggleProperty('newCustomerModal');
    },

    saveNewCustomer() {
      this.get('customerAdded')();
    },
  }
});

以及组件模板:

<div class="form-modal-content">
    <div class="el-input-wrap">
        <label class="el-input-label sr-only">Søk</label>
        {{input placeholder="Søk etter..." class="el-input"}}
    </div>
</div>

<div class="list-group">
    {{#each accounts as |account|}}
        <a href="#" class="list-group-item">
            {{account.accountName}}<br>
            {{#each account.addresses as |address|}}
                {{address.displayAddressLine}}<br>
            {{/each}}
        </a>
    {{/each}}
</div>

{{#if newCustomerModal}}
    {{#modal-dialog
            close='toggleNewCustomerModal'
            targetAttachment="none"
            translucentOverlay=true}}
        <div class="modal-full">
            <form class="form-modal" {{action 'saveNewCustomer' on='submit'}}>
                <header class="form-modal-header">
                    <a title="Close" class="modal-close" href="#" {{action 'toggleNewCustomerModal'}}>{{fa-icon 'times'}}</a>
                    <h2>Legg til kunde</h2>
                </header>

                <div class="form-modal-content clearfix">
                    <h2>{{selectedAccount.accountName}}</h2>
                </div>

                <div class="flex flex-full">
                    <button type="button" class="form-modal-button cancel" {{action 'toggleNewCustomerModal'}}>Avbryt</button>
                    <button type="submit" class="form-modal-button">Lagre</button>
                </div>
            </form>
        </div>

    {{/modal-dialog}}
{{/if}}

我不确定这是否是我犯的一个我看不到的愚蠢错误,或者是否存在错误。我相信前者。

谢谢

【问题讨论】:

  • saveNewCustomer 是在哪里定义的?请注意,动作助手将在当前控制器而不是路由上查找动作。如果您想在您的路线中实施您的操作,请使用此插件github.com/DockYard/ember-route-action-helper
  • @GerDner 哦,天哪,我不知何故完全忘记了没有在路线上采取行动。我一直在另一个项目上使用路由操作,并且已经习惯了。创建一个控制器并将动作移到那里解决了这个问题。如果您将其发布为答案,我将接受。谢谢。

标签: ember.js


【解决方案1】:

解决方案:移动控制器或使用像https://github.com/DockYard/ember-route-action-helper 这样的插件将解决问题。

原评论:saveNewCustomer 是在哪里定义的?请注意,动作助手将在当前控制器而不是路由上查找动作。如果你想在你的路由中实现你的动作,请使用这个插件

【讨论】:

  • 我将动作移至控制器。在阅读了很多关于控制器在未来一段时间内被移除的信息后,我试图避免它们。但这似乎不再是这种情况了,所以我不再那么不愿意使用控制器了。我想现在的话题是使用组件。
  • 控制器有时会被弃用。我认为它会附带可路由的组件。
猜你喜欢
  • 2023-03-31
  • 2020-05-23
  • 2022-07-25
  • 2019-02-04
  • 1970-01-01
  • 1970-01-01
  • 2021-09-05
  • 2020-09-17
  • 2021-05-17
相关资源
最近更新 更多