0

I'm just started to develeop a web app with Durandal. I don't understand how call a function from a viewmodel and why if I find an element of my document it seems is not attached yet.

Example: viewmodel.js

    define( ['libone', 'libtwo'], function () {


      $('.carousel').libone({
          expandbuttons: true,
          keyboard: true,
          mouse: true
      });

    });

It doesn't find the ID call carousel is why there's no view.hmtl content but index.html content.

Any ideas? Thanks in advance

UPDATE No errors but the view content is not returned. view.html

<section> 
  <h2 data-bind="html:name"></h2> 
  <blockquote data-bind="html:descr"></blockquote> 
    <div class="carousel"> 
      <div class="carousel-sections"> 
        <div class="carousel-section"> ... some content ... </div> 
      </div> 
    </div> 
  <a id="carousel-scroll-prev" href="#"></a> 
  <a id="carousel-scroll-next" href="#"></a> 
<section> 

modelview.js

define( ['libone', 'libtwo'], function (libone, libtwo) {
  var viewattached = function(view){
    var view = $(view);
    view.find('.carousel').libone({
      expandbuttons: true,
      keyboard: true,
      mouse: true
    });
  };

  var vm = {
    attached: viewattached,
    name: 'How about we start?',
    descr: 'You have many choices to make and many roads to cross...'
  };

  return vm;
});

Only name, descr and scroll are shown but not carousel-section.

user2312187
  • 60
  • 1
  • 13

3 Answers3

0

to gain access to the controls using jquery like you are requesting, you should use the views attached event e.g.

define( ['libone', 'libtwo'], function (libone, libtwo) {
    var viewattached = function(view){
      var view = $(view);
      view.find('.carousel').libone({
          expandbuttons: true,
          keyboard: true,
          mouse: true
      });
    };

    var vm = {
        attached: viewattached
    };

    return vm;
});

The other one that may work will be the compsitionComplete..

Excommunicated
  • 1,252
  • 8
  • 14
0

The rendering problem has been resolved using compositionComplete instead attached.

user2312187
  • 60
  • 1
  • 13
0

compositionComplete works fine.But if you refresh the page ,composition complete skips the binding of element with the carousel and teh carousel doesnt work. Any

darkHorse
  • 13
  • 8