Search code examples
sproutcore

Custom html/javascript in Sproutcore?


Is it possible to have custom html/javascript in Sproutcore?

I have to use some code from a cloud service provider.


Solution

  • Yes, this is rather easy. In your view you can define a render() method:

    App.myView = SC.View.extend({
    
      render: function(context, firstTime) {
        var someValue = `getValue`
    
        context.push(
          "<span class='mySpan'>", someValue, "</span>",
          "Any Other html/javascript that you want, can go here."
        );
    
      }
    
    })
    

    You can also use the firstTime property to know if you are rendering the first time (put out everything), or just updating the existing code.

    You can find out more: