存在: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