1

我对 ember 有点陌生。我的应用程序基本上按照我想要的方式设置,但现在我需要在页面上添加一个轮播。我将以下示例(取自 bootstrap 的示例)添加到我的模板中:

<div id="myCarousel" class="carousel slide">
    <ol class="carousel-indicators">
        <li data-target="#myCarousel" data-slide-to="0" class="active"></li>
        <li data-target="#myCarousel" data-slide-to="1"></li>
        <li data-target="#myCarousel" data-slide-to="2"></li>
    </ol>
    <!-- Carousel items -->
    <div class="carousel-inner">
        <div class="active item">A</div>
        <div class="item">B</div>
        <div class="item">C</div>
    </div>
    <!-- Carousel nav -->
    <a class="carousel-control left" href="#myCarousel" data-slide="prev">&lsaquo;</a>
    <a class="carousel-control right" href="#myCarousel" data-slide="next">&rsaquo;</a>
</div>
<div id="saveCancelBar" class="saveCancelBar"></div>

然后,当我单击下一个或上一个按钮时,我的日志中出现以下错误:

Uncaught Error: No route matched the URL 'myCarousel' ember-1.0.0-rc.2.js:22641
Router.handleURL ember-1.0.0-rc.2.js:22641
Ember.Router.Ember.Object.extend.handleURL ember-1.0.0-rc.2.js:23409
(anonymous function) ember-1.0.0-rc.2.js:23385
(anonymous function) ember-1.0.0-rc.2.js:25142
(anonymous function) ember-1.0.0-rc.2.js:4360
Ember.handleErrors ember-1.0.0-rc.2.js:411
invoke ember-1.0.0-rc.2.js:4358
tryable ember-1.0.0-rc.2.js:4547
Ember.tryFinally ember-1.0.0-rc.2.js:1102
Ember.run ember-1.0.0-rc.2.js:4551
(anonymous function) ember-1.0.0-rc.2.js:25136
jQuery.event.dispatch jquery-1.9.1.js:3074
elemData.handle

我需要做一些特别的事情来告诉 ember 来完成这项工作吗?

4

1 回答 1

1

它看起来像是您的“myCarousel”模板的缺失路线。

更新

模板

<script type="text/x-handlebars" data-template-name="application">
    {{outlet}}
</script>
<script type="text/x-handlebars" data-template-name="myCarousel">
    myCarousel
    <div id="myCarousel" class="carousel slide">
    <ol class="carousel-indicators">
        <li data-target="#myCarousel" data-slide-to="0" class="active"></li>
        <li data-target="#myCarousel" data-slide-to="1"></li>
        <li data-target="#myCarousel" data-slide-to="2"></li>
    </ol>
    <!-- Carousel items -->
    <div class="carousel-inner">
        <div class="active item">A</div>
        <div class="item">B</div>
        <div class="item">C</div>
    </div>
    <!-- Carousel nav -->
    <a class="carousel-control left" href="#myCarousel" data-slide="prev">&lsaquo;</a>
    <a class="carousel-control right" href="#myCarousel" data-slide="next">&rsaquo;</a>
</div>
<div id="saveCancelBar" class="saveCancelBar"></div>
</script>

JS

App = Ember.Application.create({});

App.IndexRoute = Ember.Route.extend({
    redirect: function(){
        this.transitionTo('myCarousel')
    }
});

App.Router.map( function() {
    this.resource('myCarousel');
});

JSFiddle:http: //jsfiddle.net/theremin/C3U5R/

于 2013-04-12T20:56:29.197 回答