방금 backbone.js로 시작했으며 현재 텍스트 입력 요소가 포함 된 div #listing_filter
페이지를 만들고 있으며 RESTful 백엔드에서 가져온 일부 목록을 보여주는 표가 있습니다 (PHP/Codeigniter). 텍스트 입력의 값은 필터로 작동하여 서버가 검색 한 결과의 범위를 좁 힙니다.사용자가 입력 값을 변경할 때 트리거 기능
문제 : 텍스트 상자의 값이 변경 될 때마다 브라우저가 필터 값을 기반으로 다른 결과 집합을 얻길 바랍니다. 아래 텍스트 입력 값이 변경된 경우에도 updateFilter
함수가 발생하지 않습니다 내 시도입니다. 어떤 아이디어가 잘못 됐나요?
또 다른 질문은 서식 파일에 #listing_filter
의 내용을 넣어야하는지, 아니면 본체 HTML에 하드 코드해야합니까? 감사!
JS 코드
window.ListingFilterView = Backbone.View.extend({
initialize: function() {
_.bindAll(this, 'updateFilter');
},
events: {
'change input' : 'updateFilter'
},
updateFilter: function() {
console.log('hey');
}
});
// Router
var AppRouter = Backbone.Router.extend({
routes: {
'': 'listings',
},
listings: function() {
//... some other code here
this.listingFilterView = new ListingFilterView();
}
});
HTML 코드
<div id="listing_filter">
Price: <input type="text" id="listing_filter_price" />
Beds: <input type="text" id="listing_filter_bedroom" />
Baths: <input type="text" id="listing_filter_bathroom" />
</div>
또는 더 간단하게 :'window.ListingFilterView = Backbone.View.extend ({el : '#listing_filter'// ...}'.btw를 사용하면 jQuery 객체를'el' 속성에 전달할 필요가 없습니다. 'var v = new V ({el : '#listing_filter'}); ' – theotheo
@ user1248256 : 참으로 오래된 습관과 모든 것. –