灰烬中的路由刷新不会清除输入控件的内容 [英] Route refresh in ember does not clear input controls content

查看:56
本文介绍了灰烬中的路由刷新不会清除输入控件的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在模板中,我有很多输入控件,例如文本框。

In a template i have many input controls like text box.

我想刷新页面,所以我叫 this.refresh( ); 在相应路由的操作哈希中。路线正在刷新(激发了模型挂钩。),但用户在文本框中输入的文本不会消失。那么刷新的意义何在?

I want to refresh the page, so i called this.refresh(); in the corresponding route's actions hash. Route is getting refreshed (model hook is fired..), but the user entered text in text boxes do not disappear. Then what is the point in refreshing?

如何使输入控件看起来像第一次加载路线时一样?

How to make the input controls appear as it is like when the route was loaded first time?

推荐答案

您需要将这些属性与模型/控制器关联。并在模型挂钩中重置模型属性,并在setupController中重置控制器属性以进行刷新。 Ember不会重绘DOM,除非它在块帮助器中,例如,如果 每个 具有 ..

You need to associate that those properties in model/controller. and reset model properties in model hook and controller properties in setupController accordingly for refresh. Ember will not redraw DOM unless it is in block helper like if each with ..

单页应用程序中的整个点都在替换值而无需重绘/刷新。这就是我们需要设计App的方式。恕我直言。

Whole point in Single Page application is replacing values without redrawing/refreshing..That's how we need to design App. IMHO.

但是总是有一些怪异的方式使之成为可能。我不会推荐这个。

But always there is hacky way in ember to make it possible. I would not recommend this.

routes / test.js

import Ember from 'ember';

export default Ember.Route.extend({
    model() {
        return { name: 'kumkan' };
    },
    actions: {
        clickRefresh() {
            this.refresh();
        }
    }
});

控制器\test.js

import Ember from 'ember';

export default Ember.Controller.extend({
    isRefreshed: true,
    actions: {
        clickRefreshh() {
            this.toggleProperty('isRefreshed');
            this.send('clickRefresh');
        }
    }
});

这里是hacky部分,

Here comes hacky part,

templates\test.hbs

{{#if isRefreshed}}
    {{test-comp model=model}}
  {{else}}
   {{test-comp model=model}}   
 {{/if}}
 <button {{action "clickRefreshh"}}> Refresh </button>
 {{outlet}}

模板\组件\test-comp .hbs

<input type="text" value="Kumkan" /> 
{{input value=model.name}}
{{yield}}

这篇关于灰烬中的路由刷新不会清除输入控件的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆