백본 및 coffeScript를 사용하여 웹 사이트를 구축하고 있는데, 한 섹션 (내부 페이지)에서 다른 섹션 (내부 페이지)으로 변경하면 새 레이아웃의보기가 대체되고 닫기 방법이 호출됩니다. 예전 것. 모든게 잘 작동하는 것 같습니다 exceptp 가정용보기에서 위젯을 다시 렌더링, 나는 twttr.widgets.load()
전화해야하고, 새로운 위젯을 매번 만들 필요가 있지만 오래된 것들이 유지되고있는 것 같아요, 만약 내가 제거해도 상관 없습니다 보기 또는 iframe 노드를 만들거나 컨테이너 요소를 비워 두십시오. 뷰를 제거하기 전에 위젯의 분리를 시도하고, 변수에 저장하고,로드 뷰를 호출 할 필요없이 위젯을 다시 배치 할 때 위젯을 배치하는 데 사용하지만 iframe 요소 만이 유일한 방법입니다. 변수에 유지되고있다 (비록 그것에 모든 것을 가지고보기를 제거하기 전에), 나는 iframe 내용을 사용하여, 노드를 복제 시도, 지금까지 모든 것이 실패했습니다. twitter obj에서 트위터 위젯을 언로드하는 메서드를 찾을 수없는 것 같습니다. 그래서 불쾌한 메모리 누수로 끝나기 때문에 홈 뷰를로드 할 때마다 최대 3MB가 추가되므로 옵션이 아닙니다. 특별히 모바일 용으로는 유령 위젯에 100MB가 할당 될 수 있습니다. 여기 백본보기에서 메모리 누수가 발생했습니다.
root = window ? global
root.Backbone.View::close =()->
@remove()
class Otalvaro.Views.BaseContent extends Backbone.View
initialize: ->
@model.bind('sync', @render, this)
내 집이다
(내가 iframe이 내용, 일반 버전을 저장하기 위해 노력하고있어이 버전에서, inMemory를 확인하지 않습니다 것은 @remove (와보기를 닫습니다) 직접 iframe이 제거)
편집 참고 : 새로운 인스턴스가 나올 때마다 위젯이 새로운 iframe을 만듭니다 (위젯 ID가 증가하기 때문에). 홈뷰 만 유지하려고합니다. 메모리, 30 프레임 이상의 고스트 iframe보다 메모리에 1 개의 iframe이있는 것이 좋습니다.
class Otalvaro.Views.Home extends Otalvaro.Views.BaseContent
template: root.template('homeTemplate')
initialize: ->
super
@inMemory = no
closeTwitterWidget: ->
$('iframe').unbind().remove()
close: =>
@$el = @$el.clone()
@el = @$el[0]
@iframe = @$el.find('iframe').contents()
@inMemory = yes
render: (callback)->
if(@inMemory)
console.log '@iframe', @iframe
else
console.log 'not in memory, doing normal rendering'
if _.isEmpty(@model.toJSON())
console.log 'model is empty, fetching it now'
@model.fetch()
else
console.log 'model fetched, now rendering'
@$el.html(@template(@model.toJSON()))
# With out the delay, the widget won't load everytime
_.delay(->
console.log 'firing twttr.widgets.load()'
root.twttr.widgets.load() # <- Guilty of all charges
, 630)
if callback? then callback(@el)
this
이것은 layoutView의 코드의 일부는, 느릅 나무 경로 변화 뷰 렌더링 : 이미 통해 인스턴스 뷰를 사용하여, 가정용
class Otalvaro.Views.MainLayOut extends Backbone.View
el: '#mainContent'
closeOldViews: ->
if @oldViews?
for view in @oldViews
console.log 'view to be closed', view
view.close()
###
# Takes an array containing one or more view instance as argument, adds a fadeOut fx to hide the current content
# then it renders each view instance from the array and extracts its node element (el) and pushes it into an array
# that is later (after the fadeIn completes) added as the html content of the layoutView
###
show: (views)->
@fadeOut()
delay = 500
viewNodes = []
for view in views
node = view.render().el
viewNodes.push(node)
_.delay(
_.bind ->
@closeOldViews()
@$el.html(viewNodes)
@fadeIn()
@oldViews = views
, this
delay)
라우터 처리기 (또한 홈 뷰 instanciating 시도 경로 변화에 있지만)
home:->
@mainLayout.show([@homeView])
null
편집을 도움이되지 않았다 : 추가 -> 홈 템플릿
<script id="homeTemplate" type="text/x-handlebars-template">
<blockquote id="homeQuote">
<p>Some Quote</p>
<footer>Catalina Otalvaro</footer>
</blockquote>
<div class="twitterFeed fadeIn">
<a href="https://twitter.com/kataotalvaro" data-widget-id="481647155510140928" class="twitter-timeline">Tweets by @kataotalvaro</a>
</div>
</script>
나는 tiwtter 개발자 포럼에서이 몇 가지 주제를 읽었지만 응답이 없으며이 문제에 익숙하지 않으므로 누구에게도이 문제를 해결하는 방법에 대한 조언이 있습니다. 정말
https://dev.twitter.com/discussions/30128 https://dev.twitter.com/discussions/5957
야아이다. load() 다시,하지만 작동하지 않았다. 그래서 실제로 뷰를 닫는 대신 닫는 메서드를 오버라이드하고, 메모리에 다시 추가하도록한다. 그러나 @ $ elat를 reatach하면 iframe. 그리고 예. widget.load()가 메모리에 없다면 호출됩니다. – Zagen
'root.twttr.widgets.load()'가 호출 된 것을 볼 수 있습니다 만,이 위젯이 홈 뷰에 추가하도록 알려주는 것은 무엇입니까? 그것은 'homeTemplate'에 있습니까? – glortho
Nopes는 twitter 위젯 코드에 의해 처리됩니다. 템플릿에 링크가 있습니다. widgets.load()를 호출하면 해당 템플릿이 발견되고 iframe으로 바뀝니다. 템플릿을 추가하기 위해 질문을 편집합니다. – Zagen