0

Ember を使用して Web アプリケーションを開発する方法を学んでいます。ご覧のとおり、私のテスト コードはビューにテキストを表示するだけです。

を使用するember-1.0.pre.jsと正常に動作しますが、に変更するember-1.0.0-pre.2.jsと、次のエラーが表示されますUncaught Error: "<TestApp.ApplicationView:ember177> - Unable to find template "application"。ember : の最新バージョンでember-latest.jsは、エラーはありませんが、テキストは表示されません。最後の 2 つのケースでは、生成された html を調べると、ハンドルバー スクリプトが処理されておらず、ブラウザーの html に残っていることがわかりました。

Ember ブログには、バージョン間の変更点が記載されていますが、どうやら私の問題とは関係がないようです。

この単純なコードが機能するようにするには、何を変更すればよいですか?

HTML

<html>
<head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <script src="http://code.jquery.com/jquery-1.7.2.js"></script>
    <script src="http://cloud.github.com/downloads/wycats/handlebars.js/handlebars-1.0.rc.1.js"></script>
    <script src="http://cloud.github.com/downloads/emberjs/ember.js/ember-1.0.pre.js"></script>
    <!--<script src="http://cloud.github.com/downloads/emberjs/ember.js/ember-1.0.0-pre.2.js"></script>-->
    <!--  <script src="http://cloud.github.com/downloads/emberjs/ember.js/ember-latest.js"></script>-->
    <script src="app.js"></script>
</head>
<body>
    <h1>Test Application</h1>
    <script  type="text/x-handlebars" data-template-name="application">
        {{outlet}}
    </script>
    <script type="text/x-handlebars" data-template-name="test">
        <h3> {{view.text}}</h3>
    </script>
</body>

JavaScript:

TestApp = Ember.Application.create();
TestApp.ApplicationController = Ember.Controller.extend();
TestApp.ApplicationView = Ember.View.extend({
    templateName: 'application'
});
TestApp.TestController = Ember.Controller.extend();
TestApp.TestView = Ember.View.extend({
    text: 'This is a sample text',
    templateName: 'test'
});
TestApp.Router = Ember.Router.extend({
    root: Ember.Route.extend({
        index: Ember.Route.extend({
            route: '/',
            connectOutlets: function(router) {
                router.get('applicationController').connectOutlet('test');
            }
        })
    })
});
TestApp.initialize();
4

1 に答える 1

0

このようにルーターを設定してみてください。

App.Router.map(function(match){
  match('/').to('application',function(match){
    match('/').to('test')
  });
});

App.TestRoute = Ember.Route.extend({
        this.render('test', {
            into:'application'
        });
})

そして、それがまったく役立つかどうかを確認してください

于 2013-01-15T08:12:33.290 に答える