6.2.5 수정 모드에서 저장 버튼 구현
수정 모드에서 [name=save] 저장 버튼을 다음과 같이 구현한다.
~/Projects/addressBook/client/addressList.js
...생략... Template.addressListItem.events({ 'click button[name=remove]' (evt,tmpl){ AddressBook.remove( { _id : this._id } ); } , 'click button[name=modify]' (evt,tmpl){ Session.set("editItem",this._id); } , /* 수정 모드에서 저장 버튼 구현 */ 'click button[name=save]' (evt,tmpl){ var address = { name : tmpl.find("input[name=name]").value ,phone : tmpl.find("input[name=phone]").value ,email : tmpl.find("input[name=email]").value ,company : tmpl.find("input[name=company]").value ,birthday : tmpl.find("input[name=birthday]").value }; AddressBook.update({_id:this._id},{$set:address}); Session.set("editItem",null); } /* 수정 모드에서 취소 버튼 구현 */ /* 뷰 모드에서 텍스트 버튼 클릭 시 수정 모드로 전환 */ }); ...생략...
텍스트 박스의 값을 업데이트한 뒤에 마지막 Session.set("editItem",null); 코드로 모드를 초기화하여 현재 라인을 뷰 모드로 바꾸었다.