3

我正在尝试使用 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}}
4

2 回答 2

4

通常将您的 DOM 脚本模式引入 Ember 是行不通的,因为 Ember 不是关于 DOM 操作,而是关于使用对象描述您的应用程序。应用程序的 DOM 表示将自动更新以反映其底层数据对象的状态。

Ember.View 使用该属性跟踪其可见性(及其子视图的可见性),isVisible并将为您处理切换它的 DOM 表示。您应该尝试揭示给定视图上下文的可见性的语义对象含义。例如,如果您决定不应该看到待办事项列表中的已完成项目,您可以:

{{#each item in controller}}
  {{view App.TodoItemView isVisibileBinding="item.isComplete"}} <a {{action kill item}}>Done!</a>
{{/each}}
于 2012-12-14T14:52:09.190 回答
-1

不要引用target

kill: function(target){   
    //I Want the selected object to hide by using Jquery hide method!!
    $(target).hide();   
    this.removeObject(target);
},

$('target')寻找<target>元素。

于 2012-12-14T07:36:13.427 回答