Requirejs 在Durandal中附加视图时如何调用函数?

Requirejs 在Durandal中附加视图时如何调用函数?,requirejs,durandal,durandal-2.0,Requirejs,Durandal,Durandal 2.0,我刚开始用Durandal开发一个web应用程序。我不明白如何从viewmodel调用函数,以及为什么如果我发现文档中的某个元素似乎还没有附加 示例:viewmodel.js define( ['libone', 'libtwo'], function () { $('.carousel').libone({ expandbuttons: true, keyboard: true, mouse: true

我刚开始用Durandal开发一个web应用程序。我不明白如何从viewmodel调用函数,以及为什么如果我发现文档中的某个元素似乎还没有附加

示例:viewmodel.js

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


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

    });
它找不到ID调用转盘,这就是为什么没有view.hmtl内容,只有index.html内容

有什么想法吗? 提前谢谢

更新 没有错误,但不返回视图内容。 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> 

只显示名称、描述和滚动,但不显示旋转部分。

要像您请求的那样使用jquery访问控件,您应该使用附加的视图事件 e、 g


另一个可能有效的方法是compsitionComplete..

使用compositionComplete而不是附件解决了渲染问题。compositionComplete工作正常。但是如果刷新页面,合成完成跳过元素与旋转木马的绑定,旋转木马不工作。
Any

我已经尝试过了,但是它返回了这个错误:uncaughttypeerror:Object#没有“find”方法,你能详细说明一下吗?未呈现您的视图?已编辑的问题与更新部分。谢谢这有什么错,为什么我调用libone函数content view not rendered?你能帮我吗?libone是你注册的另一个模块吗?它是像jquery或knockout这样的第三方库吗?
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;
});
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;
});