如何在sproutcore中向视图添加iframe?

时间:2013-08-23 00:41:44

标签: iframe sproutcore

我有一些遗留代码可以使用,我没有使用Sprout Core的经验。寻找答案已被证明是不确定的。

基本上,我只需要在现有视图中添加iframe,并且能够设置src URL。

2 个答案:

答案 0 :(得分:4)

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

例如,

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
})

答案 1 :(得分:1)

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

假设视图从SC.View延伸,最简单的可能是覆盖#render方法并自行添加iframe:

MyApp.MyView = SC.View.extend({
  render: function(context) {
    context.push("<iframe src='http://google.com' />");
  }
});
相关问题