나는 당신이 무엇을 얻고 있는지 알고 있다고 생각합니다.
// assumption: this is called on "change" event, only once
re_insert_item : function(model,m_view,collection,c_view) {
// remove the model's view from the DOM
m_view.$el.remove();
// assuming there is a comparator, sort() will move the
// model into the correct position of the collection. since
// we're not doing a .remove and .add, we have to sort manually
// (as per documentation instructions)
collection.sort();
// figure out the model that, based upon its sort position, our
// edited model will come *before*
var idx = collection.indexOf(model);
var next_model = collection.at(idx+1);
// insert our model's view into the DOM right above it's neighbour
// this assumes you have some way to get a view for a given model,
// which there isn't really a "standard" way to do (it seems)
if (next_model) {
var next_m_view = ??? // assume you have some way to get this
next_m_view.$el.before(m_view.render().$el);
}
// this model is last in the list, so just append it to the
// collection view (assuming the collection view houses the
// master list as its $el)
else {
c_view.$el.append(m_view.render().$el);
}
}
당신은에 따라 그것의 무리를 변경해야합니다 : 당신이 모델과 문제의보기에 액세스 할 수있는 가정, 여기에 기본적인 접근 방식가) 당신이 코드를 넣어 계획 곳 - 즉, 어디/함수 params를 얻는 방법; b) 모델과 뷰를 함께 연결하는 방법.
here에 (다소) 유사한 질문이 있습니다. 그러나 위의 링크로 강조 표시된 대답과 달리, 나는 그것을 피할 수 있다면 DOM traversal 코드를 사용하지 않고 대신 백본 컬렉션의 순서에 의존해야합니다.
그럼에도 불구하고 나는 이것이 당신이 찾고있는 것이라고 생각합니다. 그렇지 않은 경우 무엇이 누락되었는지 최대한 구체적으로 기재하십시오.
나는 당신의 질문을 따르지는 않지만 "전체 수집을 지우다"는 것은 무엇을 의미합니까? 추천 애트리뷰트가 변경되고 콜렉션 뷰에서'sort' 이벤트를 리스닝하고'render'를 호출 할 때 콜렉션에서'sort'를 호출 할 수없는 이유는 무엇입니까? – fbynite
질문을 수정하여 더 명확하게하려고합니다. 이것은 실제로 뷰 문제이며 콜렉션/정렬 문제는 아닙니다. 분명히 나는 자신을 올바르게 설명하지 못했습니다. 바라기를 바란다. – EleventyOne
DOM 요소의 정렬 순서를 변경 하시겠습니까? – kinakuta