存在:2500個數組對象項。 Render方法把1347.783ms可觀察vs渲染方法jsviews
I`ve試圖優化使用$ .observable(陣列).REFRESH()方法的定時和花費:3382.213ms
什麼`的最佳方式來更新視圖?我認爲refresh()方法隻影響不多的變化項目。
模板:
<script id="betTMPL" type="text/x-jsrender">
<div class="bet_group">
<div class="bet-title {{if hideGroup}}min{{/if}}" id="group_{{:groupID}}" data-gid="{{:groupID}}" data-gameid="{{:gameID}}">
<div class="groupName">{^{:groupName}}
<span id="kolG_{{:groupID}}" {{if !hideGroup}}style="display: none;"{{/if}}> ({{:betsLen}})</span>
{^{if allowMyMarkets}}
{^{if actionMyMarket}}
<span class="addToMarket" title="<?=__('Add')?>"></span>
{{else}}
<span class="addToMarket active" title="<?=__('Del')?>"></span>
{{/if}}
{{/if}}
</div>
</div>
<div class="bets" {{if hideGroup}}style="display: none"{{/if}}>
{^{for bets ~cols=cols ~mainGame=mainGame ~idd=idd ~gameID=gameID ~groupID=groupID}}
{{if !(#getIndex() % (~cols))}}
{{if #getIndex() != 0}}
</div>
{{/if}}
<div>
{{/if}}
{^{if #data}}
<div id="z_{{:T}}">
<span class="bet_type {{:spanBetClass}}">{^{:betName}}
<span class="koeff {{:classLight}}"
{{if ~mainGame}}mainGame="{{:~mainGame}}"{{/if}}
{{if DopName}}dopName="{{:DopName}}"{{/if}}
bl="{{:B}}"
u="{{:~idd}}"
idgamecfg="{{:~gameID}}"
v="{{:sobID}}"
g="{{:~groupID}}"
d="{{:P}}"
dn="upcoming_events"
pl="{{:Pl.Id}}"
data-type="{{:T}}"
data-coef="{{:C}}"
id="b_{{:newID}}"><i>{^{:CV}}</i></span>
</span>
</div>
{{else}}
<div> </div>
{{/if}}
{{if #getIndex() == #get("array").data.length - 1}}
</div>
{{/if}}
{{/for}}
</div>
</div>
</script>
欣賞你的答案。 我已經做了一個小提琴,完全解決我的問題。 你能否請建議解決的方法。 合併相同的數據 - 鏈接:1779.328ms 合併:6253.951ms https://jsfiddle.net/bc335zyx/2/ – user2879626
感謝提供的jsfiddle。我正在調查。不幸的是,移動和編譯的視圖模型方法實際上並未針對數組進行優化(I misspoke) - 因此{^ {for}}塊將爲整個數組重新渲染。有可能在JsViews更新中改變它 - 但我不能承諾。正在處理它...我更新了我的回覆以上... – BorisMoore
好消息 - 我能夠做優化工作,並且它是最新版本:https://github.com/BorisMoore/jsviews/commit/91d5e6309d7b4d93c9d51117201cd42142429601 。上述jsfiddle中的合併現在需要271ms。我會相應地更新我的答案 – BorisMoore