したがって、私はアプリケーションでBackbone.jsを使用しています。私はセグメントをURLに関連付ける。したがって、セグメントには多くのURLを含めることができ、任意のセグメントに任意のURLを入れることができます.URLペインとセグメントペインがあります。問題はハイライト部分です。したがって、セグメントをクリックすると、そのセグメントのURLを強調表示したいと思います。私はページに表示されるURLの数を200に制限しています。200を超えるURLがある場合は、ユーザーに最初の200を表示し、残りのユーザーはライブ検索を使用して、探しているURLを見つけます。問題は、200未満のURLがあり、セグメントをクリックすると強調表示が機能することです。 200以上のURLがあり、ユーザーがセグメントをクリックすると、強調表示は機能しません。 200以上のURLがある場合はコレクションのスライスを使用していますが、最初の200を強調表示しても機能しません。コードスニペットは次のとおりです。誰かがこれを修正する方法に関する良い提案はありますか? toggleSelection機能についてSegmentView.jsでBackbone.jsのハイライト表示がページ内の多くのデータで壊れていた
:
toggleSelection: function() {
var max = 200;
//get the urls
var urls = this.App.segmentUrlCollection.urlsForSegment(this.model);
var pixels = this.App.segmentPixelCollection.pixelsForSegment(this.model);
if (this.selected) {
this.deselect();
this.selected = false;
this.$('.summary').removeClass('selected');
this.App.segmentCollection.each(function(segment){
if (segment.get('name') == "Unmapped"){
segment.view.$('.summary').addClass('unmapped');
}
});
//If there are more than 200 urls in url Collection just highlight the first 200.
if (this.App.urlCollection.size > 200) {
//problem?
this.App.urlCollection.slice(0,199).each(function(url) {
if (url.view.App.isUrlUnmapped(url)) {
url.view.$('.summary').addClass('unmapped');
}
});
}
else {
this.App.urlCollection.each(function(url) {
if (url.view.App.isUrlUnmapped(url)) {
url.view.$('.summary').addClass('unmapped');
}
});
}
//deselect the urls
_(urls).each(function(url) {
url.view.deselect();
});
_(pixels).each(function(pixel) {
pixel.view.deselect();
});
} else {
this.App.segmentCollection.each(function(segment) {
segment.view.selected = false;
segment.view.deselect();
});
this.App.segmentCollection.each(function(segment){
if (segment.view.$('.summary').hasClass('unmapped')){
segment.view.$('.summary').removeClass('unmapped');
}
});
//If there are more than 200 urls in url Collection just highlight the first 200.
if (this.App.urlCollection.size > 200) {
//problem?
this.App.urlCollection.slice(0,199).each(function(url) {
if (url.view.$('.summary').hasClass('unmapped')) {
url.view.$('.summary').removeClass('unmapped');
}
// url.view.deselect();
});
}
else {
this.App.urlCollection.each(function(url) {
if (url.view.$('.summary').hasClass('unmapped')) {
url.view.$('.summary').removeClass('unmapped');
}
// url.view.deselect();
});
}
//If there are more than 200 urls in url Collection just highlight the first 200.
if (this.App.urlCollection.size > 200) {
//problem?
this.App.urlCollection.slice(0,199).each(function(url) {
url.view.deselect();
});
}
else {
this.App.urlCollection.each(function(url) {
url.view.deselect();
});
}
this.App.pixelCollection.each(function(pixel) {
pixel.view.deselect();
});
this.select();
this.selected = true;
this.$('.summary').addClass('selected');
//select the urls
_(urls).each(function(url) {
url.view.select();
});
_(pixels).each(function(pixel) {
pixel.view.select();
});
}
return false;
}
を呼び出すことによって、コレクションからモデルの配列のコピーを入手することができますが、あなたの提案のためにありがとうございました。私はそれを試み、Firebugのコンソールを見て、 "url.view is undefined"というエラーを見ました "if(url.view。$( '。summary')。hasClass( 'unmapped')){" –