我一直想知道在Ember.js中如何更改HTML变量的值。我想要做的是,当我单击编辑按钮时,我想更改readonly的值并使用视图 Ember.TextField 使其在文本字段上可读。
代码如下所示:
<div id="list_container">
<h2>Contacts:</h2>
<ul id="people_List">
{{#each person in controller}}
<li {{bindAttr class='isEditing:red'}}>
<!-- here where Im trying to use the value to switch the value from a html variable -->
{{view Ember.TextField valueBinding="person.name" readonly='isEditing'}}
{{view Ember.TextField valueBinding="person.birthday" readonly='isEditing'}}
{{view Ember.TextField valueBinding="person.telephone" readonly='isEditing'}}
<button {{action edit}}>Edit</button>
<button {{action details}}>Details</button>
<button {{action remove}}>Remove</button>
</li>
{{/each}}
</ul>
</div>
Schedule.PeopleController = Ember.ArrayController.extend({
itemController: 'Person'
});
Schedule.PersonController = Ember.ObjectController.extend({
isEditing: true,
edit : function () {
this.toggleProperty('isEditing');
console.log(this.get('isEditing'));
},
details : function () {
console.log("Details was clicked!!");
},
remove : function () {
console.log("Remove was clicked!!");
}
});
我避免使用:
{{if}}
...HTML CODE...
{{else}}
...HTML CODE...
{{/if}}