2014-02-10 2 views
1

나는 {{#each}} 루프로 생성 된 테이블을 가지고 있으며 사용자의 이름과 성을 표시합니다. 해당 행의 레코드를 삭제하려면 삭제 버튼을 추가하고 싶습니다. EmberFire를 사용하여 Firebase에 연결합니다.Ember.js 및 EmberFire로 양식 생성

해당 행의 데이터를 해당 삭제 버튼과 연결하는 가장 좋은 방법은 무엇입니까?

는 Heres는 관련 코드의 조금이라도 나는이 :

index.html

{{#each}} 
    <tr> 
    <td> 
     {{this.first}} 
    </td> 
    <td>{{this.last}}</td> 
    <td> 
     <button>X</button> 
    </td> 
    </tr> 
{{/each}} 

router.js

App.IndexRoute = Ember.Route.extend({ 
    model: function() { 
    return EmberFire.Array.create({ 
     ref: new Firebase(FirebaseRef + 'testObj') 
    }); 
    }, 
    renderTemplate: function() { 
    this.render('index'); 
    this.render('users', { 
     outlet: 'users', 
     into : 'index' 
    }); 
    } 
}); 

controller.js

App.IndexController = Ember.ArrayController.extend({ 
    actions: { 
    register: function() { 
     this.pushObject({ 
     'first' : this.get('firstName'), 
     'last' : this.get('lastName') 
     }); 
    } 
    } 
}) 

감사!

답변

4

당신은 당신의 인 IndexController에 삭제 작업을 추가 할 수 있습니다

App.IndexController = Ember.ArrayController.extend({ 
    actions: { 
    register: function() { 
     this.pushObject({ 
     'first' : this.get('firstName'), 
     'last' : this.get('lastName') 
     }); 
    }, 
    delete: function(person) { 
     this.content.removeObject(person); 
    } 
    } 
}) 

그런 다음 당신의 index.html을에 다음을 추가합니다

{{#each}} 
    <tr> 
    <td> 
     {{this.first}} 
    </td> 
    <td>{{this.last}}</td> 
    <td> 
     <button {{action "delete" this}}>X</button> 
    </td> 
    </tr> 
{{/each}} 
+0

그래를, 그것을 행한! 나는 각 행에 일종의 수동 데이터 바인딩을해야한다고 가정했는데 버튼이 그것이다. 나는 Ember의 마법에 이걸 집어 넣을거야 :) 고마워! – JDillon522

+0

@ JDillon522 기뻤습니다! – Sara