0
我有一个users
模板,这是一个用户表。在该表下是创建新用户的链接。为了更好的用户体验,我想通过使用class="disabled"
来禁用它,或者在创建新用户时隐藏该链接。什么是最好的方式来做到这一点?隐藏用户期间的链接。新
的index.html
<script type="text/x-handlebars" data-template-name="users">
<div class='row'>
<div class='span7'>
<table class='table table-striped'>
<tbody>
{{#each model itemController="user"}}
<tr {{bindAttr class="isDirty:warning"}}>
<td>{{lastName}}</td>
</tr>
{{/each}}
</tbody>
</table>
<p>
{{#linkTo 'users.new' classNames="btn btn-small"}}Create a new user{{/linkTo}}
</p>
</div>
<div class='span5'>
{{outlet}}
</div>
</div>
</script>
<script type="text/x-handlebars" data-template-name="users/new">
<p><strong>Last name</strong><br>{{view Ember.TextField valueBinding=lastName}}</p>
<p>
{{#if isDirty}}
<button {{action 'save' this}} class="btn btn-small">Save</button>
{{else}}
<button class="btn btn-small disabled">Save</button>
{{/if}}
</p>
</script>
app.js
App.UsersRoute = Ember.Route.extend({
model: function() {
return App.User.find();
}
});
App.UsersNewRoute = Ember.Route.extend({
model: function() {
return App.User.createRecord();
},
renderTemplate: function() {
this.render({ into: 'users' });
}
});
App.UsersNewController = Ember.ObjectController.extend({
save: function(model) {
model.get('transaction').commit();
App.Router.router.transitionTo('users.index')
}
});
当'users.new'中定义模型时,如何在'users'模板中使用'isNew'检查? – wintermeyer 2013-05-06 21:36:28
谢谢!我希望“少代码”版本,但它像一个魅力。 – wintermeyer 2013-05-06 21:58:10
也许有一个更简洁的版本,但我没有记住它... – 2013-05-06 22:00:50