我使用{{> ArticleForm}}在阿拉伯语-俄语词典中创建和更新文章。在Autoform插件出现问题之后,我在模板中使用blaze和ReactiveDict。

首先,我将其用于更新Article,一切正常。现在,我为创建文章添加了相同的表单。我将{{> ArticleForm}}放置到{{> Header}}组件中的引导程序模版中,并通过顶部菜单中的“ + Add”按钮进行调用。打开我的表格。第一条的插入效果很好。在DB中有一篇新文章,甚至我也重定向到了新文章。但是在第二次调用时,template.data为空并且表单不是交互式的,它会引发错误,因为更新任何字段后,ArticleForm应该从template.data中写入ReactiveDict,但它不存在。我不明白,fir成功插入后template.data会去哪里...。如果有人知道,请回答...

外观如下:

 

这是我形式的数据上下文:



Template.ArticleForm.helpers({
  article() {
    console.log("helper-article");
    if (!this.words) this.words = [{ note: "", word: "" }];
    if (!this.translations) this.translations = [{ translation: "" }];
    if (!this.synonyms) this.synonyms = [];
    if (!this.roots) this.roots = [];
    if (!this.subjects) this.subjects = [];
    //newWords, newTranslations - это добавление имен к элементам формы,
    //по которым можно будет отслеживать все изменения в форме
    let newWords = this.words.map((elem, index) => {
      return { note: elem.note, word: elem.word, wordId: `words.${index}` };
    });
    let newTranslations = this.translations
      ? this.translations.map((elem, index) => {
          return {
            translation: elem.translation,
            translationId: `translations.${index}.translation`,
            examples: elem.examples
              ? elem.examples.map((elem2, index2) => {
                  return {
                    example: elem2.example,
                    translation: elem2.translation,
                    exampleId: `translations.${index}.examples.${index2}`
                  };
                })
              : []
          };
        })
      : [];

    this.words = newWords;
    this.translations = newTranslations;
    this.picture = Session.get("picture");
    Template.instance().reactiveForm.set("article", this);
    const article = Template.instance().reactiveForm.get("article");
    return article;
  },
  deleted() {
    return this.deleted ? "checked" : "";
  },
  showMiddleHarakat(speachPart, index) {
    return speachPart == "глагол, I порода" && index == 0;
  },
  picture() {
    return Session.get("picture");
  }
});





这是我的模板{{> ArticleForm}}



<template name="ArticleForm">
        <form id="articleForm-{{_id}}" class="panel panel-default article {{#if notPublished}}-opacity-06{{/if}}">
          <div class="panel-heading">
                <div class="panel-title words">
                    <div class="label label-info speach-part">{{speachPart}}</div><br />
                    <!-- Глагол 1й породы имеет дополнительную информацию для вывода, поэтому
                    особый шаблон его вывода, например, среднекорневую глассную и масдары -->
                        {{#each article.words}}
                                <div class="wordEdit editField" id="{{wordId}}">
                                    <i class="glyphicon glyphicon-remove remove-word -remove" id="remove.{{wordId}}"></i>
                                    <input type="text" placeholder="прим." value="{{note}}" name="{{wordId}}.note" class="form-control note">
                                    <input type="text" placeholder="слово" value="{{word}}" name="{{wordId}}.word" class="form-control word -arabic-text-mid">
                                </div>
                            {{#if showMiddleHarakat ../speachPart @index}}
                                <div class="note middleHarakat" title="среднекорневая гласная настоящего времени">
                                        <input type="text" placeholder="скгнв" value="{{../middleHarakat}}" name="middleHarakat" class="form-control note">
                                </div>
                            {{/if}}
                        {{/each}}
                        <div class="add-word">
                                <i class="glyphicon glyphicon-plus"></i>
                        </div>
                </div>
          </div>
          <div class="panel-body">
                <div class="translations">
                    {{#each article.translations}}
                        <div class="translation">
                                <div class="editField editTranslation" id="{{translationId}}">
                                    <input type="text" name="{{translationId}}" value="{{translation}}" class="form-control" placeholder="перевод">
                                    <i class="glyphicon glyphicon-remove remove-translation -remove" id="remove.{{translationId}}"></i>
                                </div>

                                <div class="examples examples-form-{{../_id}}-{{@index}}">
                                        {{#each examples}}
                                            <div class="exampleEdit editField" id="{{exampleId}}">
                                                    <input type="text" placeholder="пример" value="{{example}}" name="{{exampleId}}.example" class="form-control example -arabic-text-mid">
                                                    <input type="text" placeholder="перевод примера" value="{{translation}}" name="{{exampleId}}.translation" class="form-control translation">
                                                    <i class="glyphicon glyphicon-remove remove-example -remove" id="remove.{{exampleId}}"></i>
                                            </div>
                                        {{/each}}
                                        <button class="btn btn-default btn-xs add-example" id="addExampleFor.{{translationId}}">
                                                <i class="glyphicon glyphicon-plus"></i>Пример
                                        </button>
                                </div>
                        </div>
                    {{/each}}
                    <button class="btn btn-default btn-sm add-translation">
                            <i class="glyphicon glyphicon-plus"></i>Перевод
                    </button>
                </div>
                {{> TagsSubjects}}
                {{> TagsSynonyms}}
                {{> TagsRoots}}
                <!--
                <div class="uploadImage">
                    {{> uploadForm}}
                    picture: {{picture}}
                </div>
                -->
          </div>
          <div class="panel-footer">
            <button class="btn btn-primary article-save">Сохранить</button>
            <button class="btn btn-default article-edit-cancel">Отмена</button>
          </div>
        </form>
</template>

最佳答案

这可能是因为模式关闭时您没有正确清除表单模板吗?请记住,模态只是隐藏的,不会删除模板。

boostrap modal package添加AutoForm支持时遇到了类似的问题。

10-07 20:16