如何将iframe添加到sproutcore中的视图?

如何将iframe添加到sproutcore中的视图?,iframe,sproutcore,Iframe,Sproutcore,我有一些遗留代码要处理,但我没有使用Sprout Core的经验。寻找答案被证明是没有结果的 基本上,我只需要在已经存在的视图中添加一个iframe,并能够设置src URL 有几种方法可以做到这一点 假设视图从SC.view扩展,最简单的方法可能是重写该方法并自己添加iframe: MyApp.MyView = SC.View.extend({ render: function(context) { context.push("<iframe src='http://goog

我有一些遗留代码要处理,但我没有使用Sprout Core的经验。寻找答案被证明是没有结果的


基本上,我只需要在已经存在的视图中添加一个iframe,并能够设置src URL

有几种方法可以做到这一点

假设视图从
SC.view
扩展,最简单的方法可能是重写该方法并自己添加iframe:

MyApp.MyView = SC.View.extend({
  render: function(context) {
    context.push("<iframe src='http://google.com' />");
  }
});
MyApp.MyView=SC.View.extend({
渲染:函数(上下文){
上下文。推送(“”);
}
});

有几种方法可以做到这一点

假设视图从
SC.view
扩展,最简单的方法可能是重写该方法并自己添加iframe:

MyApp.MyView = SC.View.extend({
  render: function(context) {
    context.push("<iframe src='http://google.com' />");
  }
});
MyApp.MyView=SC.View.extend({
渲染:函数(上下文){
上下文。推送(“”);
}
});

虽然您可以使用
渲染
功能非常轻松地渲染固定iframe,但也有一个SproutCore视图,
SC.WebView
,它可以在
:desktop
框架中为您执行此操作。如果希望
src
发生更改,或者希望调整iframe的大小以匹配其内容的大小,则应使用
SC.WebView

比如说,

myWebView: SC.WebView.extend({
  layout: { left: 10, right: 10, top: 10, bottom: 10, border: 1 },
  shouldAutoResize: true, // when the iframe loads, resize it to fit the size of its content
  valueBinding: SC.Binding.oneWay('MyApp.currentUrl') // bind the 'src' of the iframe
})

虽然您可以使用
render
功能非常轻松地渲染固定iframe,但还有一个SproutCore视图
SC.WebView
,它可以在
:desktop
框架中为您执行此操作。如果希望
src
发生更改,或者希望调整iframe的大小以匹配其内容的大小,则应使用
SC.WebView

比如说,

myWebView: SC.WebView.extend({
  layout: { left: 10, right: 10, top: 10, bottom: 10, border: 1 },
  shouldAutoResize: true, // when the iframe loads, resize it to fit the size of its content
  valueBinding: SC.Binding.oneWay('MyApp.currentUrl') // bind the 'src' of the iframe
})

(旁注:我假设shouldAutoResize属性只适用于相同来源的内容。我相信在跨来源的情况下,调整大小会失败,尽管最坏情况下你是安全的。)(旁注:我假设shouldAutoResize属性只适用于相同来源的内容。我相信在跨来源的情况下,调整大小会失败,尽管最坏情况下你是安全的。)