因此,當我點擊模板上的按鈕時,應該更改一個值並在屏幕上顯示記錄列表。這沒有發生。我究竟做錯了什麼?以下是我的控制器,模型,模板和路線的代碼。如何使用車把(EmberJS)
控制器:
import Ember from 'ember';
export default Ember.Controller.extend({
usernameIn: '',
passwordIn: '',
found: '',
display: false,
actions:{
renderNotes(){
this.display = true;
}
}
});
路線:
import Ember from 'ember';
export default Ember.Route.extend({
model()
{
return this.store.findAll('note');
}
});
模板:
<h1>Login:</h1>
<h3>Username:</h3>{{input type="text" value = keyInput size="50"}}
<h3>Password:</h3>{{input type="text" value = keyInput size="50"}}
<br>
<br>
<button{{action 'renderNotes'}}>Submit</button>
{{#if display}}
<thead>
<tr>
<th>Username</th>
<th>Note</th>
</tr>
</thead>
<tbody>
{{#each model as |found|}}
<tr>
<th>{{found.username}}</th>
<td>{{found.note}}</td>
</tr>
{{/each}}
</tbody>
{{/if}}
{{outlet}}
型號:
import DS from 'ember-data';
export default DS.Model.extend({
note: DS.attr('string'),
username: DS.attr('string'),
password: DS.attr('string')
});
我們怎樣才能讓這個按鈕切換顯示?這是可能的,沒有寫作的動作?我要求這個只是爲了確認 – kumkanillam
是的,這是可能的,沒有寫作的動作。只需將'action'助手與'mut'助手結合起來就像我上面所示。你可以閱讀更多關於'mut' helper [here](http://emberjs.com/api/classes/Ember.Templates.helpers.html#method_mut)和'action' helper [here](http:// emberjs.com/api/classes/Ember.Templates.helpers.html#method_action)。 – rmmmp
在您的代碼中,true是硬編碼的。我沒有找到切換顯示屬性的方法。可能是我應該問這個新的問題,但! – kumkanillam