Ember js 表单保留旧值



我在SO上尝试了其他答案,但没有一个帮助。

app/routes/card/new.js
actions: {
  save(title, description) {
    const newCard = this.get('store').createRecord('card', { title, description } );
    newCard.save().then((card) => {
      this.transitionTo('card.card', card);
    });
  }
}

对于视图,我有:

app/templates/card/new.hbs
<form>
  <fieldset class="form-group">
    <label for="card-title">Card Title</label>
    {{input type="text" value=title class="form-control" id="card-title" placeholder="Enter the title of the card"}}
    <small class="text-muted">Give your card a nice title</small>
  </fieldset>
  <fieldset class="form-group">
    <label for="card-description">Card Description</label>
    {{textarea value=description class="form-control" id="card-description" rows="3"}}
    <small class="text-muted">Describe your card</small>
  </fieldset>
  <div class="btn-group" role="group" aria-label="Save or Cancel your card">
    <button {{action 'save' title description}} class="btn btn-secondary">Save</button>
    <button {{action 'cancel'}} class="btn btn-danger">Cancel</button>
  </div>
</form>

当我创建卡片时,它工作正常,但是当我再次尝试创建新汽车时,表单保留了刷新时消失的旧值。

app/routes/card/new.js

model(){
  return this.get('store').createRecord('card');
}

应用/控制器/卡/新增.js

actions: {
  save(){
   this.get('model').save().then((card) => {
      this.transitionTo('card.card', card);
    });
}
}

app/templates/card/new.hbs

<form>
  <fieldset class="form-group">
    <label for="card-title">Card Title</label>
    {{input type="text" value=model.title class="form-control" id="card-title" placeholder="Enter the title of the card"}}
    <small class="text-muted">Give your card a nice title</small>
  </fieldset>
  <fieldset class="form-group">
    <label for="card-description">Card Description</label>
    {{textarea value=model.description class="form-control" id="card-description" rows="3"}}
    <small class="text-muted">Describe your card</small>
  </fieldset>
  <div class="btn-group" role="group" aria-label="Save or Cancel your card">
    <button {{action 'save'}} class="btn btn-secondary">Save</button>
    <button {{action 'cancel'}} class="btn btn-danger">Cancel</button>
  </div>
</form>

最新更新