我正在尝试使用 jQuery 方法 hide()
隐藏一个对象,但它不起作用。
我使用 console.log() 检查被调用函数中参数的值,所以我知道我做的不对。但是,我不知道如何让它工作......
这是我所拥有的:
#------------------------Model------------------------
App.Monster = Ember.Object.extend({
name: "",
hp: 0,
isDead : false,
isDeadChanged: function(target, value){
App.monstersController.kill(target);
}.observes('isDead')
});
#------------------------Controller------------------------
App.monstersController = Ember.ArrayProxy.create({
content:[],
createMonster: function(name,hp){
var monster = App.Monster.create({name:name});
this.pushObject(monster);
},
kill: function(target){
//I Want the selected object to hide by using Jquery hide method!!
$('target').hide();
this.removeObject(target);
},
#------------------------HTML FILE------------------------
{{#each App.monstersController contentBinding="App.monstersController.content" tagName="ul"}}
<li>
{{view Ember.Checkbox checkedBinding="isDead"}}
<label for="" {{bindAttr class="isDead"}}>{{name}}</label>
</li>
{{/each}}
最佳答案
通常将您的 DOM 脚本模式引入 Ember 是行不通的,因为 Ember 不是关于 DOM 操作,而是关于使用对象描述您的应用程序。您的应用程序的 DOM 表示将自动更新以反射(reflect)其底层数据对象的状态。
Ember.View 使用 isVisible
属性跟踪其可见性(及其 subview 的可见性),并将为您处理切换它的 DOM 表示。您应该尝试揭示给定 View 上下文可见性的语义对象含义。例如,如果您决定不应该显示待办事项列表中已完成的项目,您可以:
{{#each item in controller}}
{{view App.TodoItemView isVisibileBinding="item.isComplete"}} <a {{action kill item}}>Done!</a>
{{/each}}
关于javascript - 我如何在 Ember.js 中调用 jQuery 的 hide() 方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13874459/