【问题标题】:Select2 autoform creates an infinite loop and it's not reactiveSelect2 autoform 创建一个无限循环,它不是反应式的
【发布时间】:2017-09-02 16:49:12
【问题描述】:

我有一个包含另外两个表单的表单,我需要在更新第二个表单时以这种方式在第一个表单中显示该信息:

1) 主要形式:

{{#autoForm collection=company doc=company id='mainForm' type=formType}}
 {{> uploadLogoForm }}
 {{> afQuickField
   name='company.logoUrl'
   class='fu-select-tag--background-image'
   label='Select a logo'
   type='select'
   options=logoOptions
   template='plain'}}
{{/autoform}}

2) 第二种形式:

 <template name="uploadLogoForm">
  {{#autoForm collection=collection id="newLogoForm" type="normal" class="fu-form-upload"}}
    {{> afQuickField
     name="_id"
     accept=".png,.gif,.svg"
     label="Upload a logo"
     type="slingshot"
     directive="logos"}}
  {{/autoForm}}
</template>

因此,如果我在 uploadLogoForm 中上传徽标,则该徽标应使用此助手在主表单中显示/选择:

Template.mainForm.helpers({
 logoOptions() {
   const company = getCompany();
   const logoUrls = [];
   let currentLogoUrl;

   if (company) {
    currentLogoUrl = company.company.logoUrl;
   }

   const uploadedLogo = AutoForm.getFieldValue('_id', 'newLogoForm');
   if (uploadedLogo) {
    currentLogoUrl = getPath(uploadedLogo);
   }

   if (currentLogoUrl) {
    logoUrls.push(currentLogoUrl);
   }

   if (FlowRouter.subsReady('logos')) {
     Logo.find({}, {sort: {_id: 1}}).forEach(logo => {
       const logoUrl = getPath(logo._id);

       if (!_.include(logoUrls, logoUrl)) {
         logoUrls.push(logoUrl);
       }
     });
  }

  return logoUrls.map(logoUrl => ({
   label: logoUrl,
   value: logoUrl,
   selected: logoUrl === currentLogoUrl ? true : null
 }));
}});

如果快速字段的类型是“选择”,这很好用但是当我使用“选择2”时,会发生很多奇怪的事情,比如帮助程序中的无限循环并且选择元素为空。我必须手动选择元素或文件才能修复它。

【问题讨论】:

    标签: javascript meteor select2 meteor-autoform


    【解决方案1】:

    我们终于找到了问题所在。 Select2 不关心 attr(selected) 只关心值。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-01-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-14
      • 2017-01-05
      相关资源
      最近更新 更多