Quantcast
Channel: Ember.JS - Latest topics
Viewing all articles
Browse latest Browse all 4827

Force method to execute again

$
0
0

@nullnillzero wrote:

All,
I'm struggling with the ember js workflow. Specifically I'm working with a proprietary JavaScript API that asyncronously renders content into a container of my choosing. When using this API in a template it only renders the first time. Where other, more simple, JavaScript seems to execute each time the template is shown.

Take the following for example

HelloRandom.hbs

<script>
  function getRandom(min, max) {
      return Math.random() * (max - min) + min;
  }

  $('#someContent).html('Hello ' + getRandom(1, 100));
</script>

The above works as intended, I navigate to http://localhost:4200/HelloRandom and a random number is generated. I then navigate to anywhere else in the application and back to HelloRandom and a new random number is generated.

If I plugin my code to the same template then it is only executed once and never again. I will post what I can here

index.html

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    {{content-for "head"}}

    <link rel="stylesheet" href="{{rootURL}}assets/vendor.css">
    <script type='text/javascript' language='JavaScript' src='http://localhost/myapi'></script>

    {{content-for "head-footer"}}
  </head>
  <body>
    {{content-for "body"}}

    <script src="{{rootURL}}assets/vendor.js"></script>

    {{content-for "body-footer"}}
  </body>
</html>

HelloAPI.hbs

<script>
  myAPI.load('module');
  var ops = new myAPI.setOptions();
  ops.setType('open');
  ops.setDB('myDB');
  myAPI.init('url', ops == undefined ? null : ops, null, null, function() {
    "use strict";

    var myContent = new myAPI.RenderContent('someContent');
    myAPI.submit();
  });
</script>

I'm thinking that this might have something to do with the fact that myAPI.load('module') is in the template and causing issues. So I removed it and added it to in index.html but my API then complains that 'module' is not loaded.

I wish I could give more detail on my code, any help is appreciated.

Posts: 2

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 4827

Trending Articles