2014-02-20 4 views
3

Я пытаюсь определить вложенный ресурс в наборе приложений ember. Неверна ли моя файловая структура? Когда я добавить вложенный ресурс, я получаю следующее исключение:Набор приложений и маршруты ресурсов Ember

Error: Assertion Failed: The URL '/pages.index' did not match any routes in your application 

Простым комментированием функцию определения вложенного «страницы» ресурс, приложение загружает правильно и отображает шаблон страницы. Код

Маршрутизатор:

var Router = Ember.Router.extend(); 

Router.map(function() { 
    this.route('component-test'); 
    this.route('helper-test'); 
    this.resource('pages', {path: '/pages'} 
     // if this line is commented out, no error (index route is not called though) 
     , function() { this.resource('page', {path: ':page_id'}); } 
    ); 
}); 

export default Router; 

структура файла таким образом:

$ ls -R 
component-test.js helper-test.js  pages 
component_test.js index.js  pages.js 

./pages: 
index.js page.js 

Страницы маршрута:

export default Ember.Route.extend({ 

    model: function() { 
    return [{title: "One", _id: "one"}, {title: "Two", _id: "two"}]; 
    //this.store.find('page'); 
    } 

}); 

страницы/индекс маршрута:

export default Ember.Route.extend({ 
    model: function() { 
    return this.modelFor('page'); 
    } 
}); 

ES6 порожденный модуль для маршрута страницы/индекса выглядит следующим образом:

define("appkit/routes/pages/index", 
    ["exports"], 
    function(__exports__) { 
    "use strict"; 
    __exports__["default"] = Ember.Route.extend({ 
     model: function() { 
     return this.modelFor('page'); 
     } 
    }); 
    }); 
+0

Каково было ваше решение? –

ответ

4

Попробуйте это.

У вас есть указатель на индексный указатель с именем "index.js" в папке с папками?

Ember App Kit ищет файлы по структуре папок. Таким образом, индексный маршрут страниц должен быть найден в «app/routes/pages/index.js».

Вот репо с этим кодом https://github.com/kiwiupover/for_eric

Маршрутизатор

var Router = Ember.Router.extend(); 

Router.map(function() { 
    this.route('component-test'); 
    this.route('helper-test'); 
    this.resource('pages', function() { 
    this.route('new'); 
    }); 
}); 

export default Router; 

Маршруты Папка

routes -|  //folder 
    pages.js  
    pages -|  // folder 
    index.js 

страницах маршрута

export default Ember.Route.extend({ 
    model: function(){ 
    return [{title: "One", _id: "one"}, {title: "Two", _id: "two"}]; 
    } 
}); 

индексные страницы маршрута

export default Ember.Route.extend({ 
    model: function(){ 
    return this.modelFor('pages'); 
    } 
}); 

Шаблон Папка

templates -|  //folder 
    pages.hbs  
    pages -|  // folder 
    index.hbs 

Страницы шаблона

<h1>Pages</h1> 
<ul> 
    {{#each}} 
    <li>{{title}}</li> 
    {{/each}} 
</ul> 

{{outlet}} 

Индекс Шаблон

<h2>The Index page for Pages</h2> 

<ul> 
    {{#each}} 
    <li>the index page {{title}}</li> 
    {{/each}} 
</ul> 
+0

Да, это то же самое, что и у меня. Теперь я понял, благодаря вашей помощи. – Artzt

Смежные вопросы