Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ember.js/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ember.js 为什么插座不能访问模型数据?_Ember.js - Fatal编程技术网

Ember.js 为什么插座不能访问模型数据?

Ember.js 为什么插座不能访问模型数据?,ember.js,Ember.js,我有一个JSFIDLE,在这里我试图呈现一个节点模板: <script type="text/x-handlebars" data-template-name="node"> <h1>Node template</h1> <p>The outlet comes here:</p> {{outlet}} </script> 节点模板 出口在这里: {{outlet}} 这应该呈现一个节点/

我有一个JSFIDLE,在这里我试图呈现一个节点模板:

  <script type="text/x-handlebars" data-template-name="node">
    <h1>Node template</h1>
    <p>The outlet comes here:</p>
    {{outlet}}
  </script>

节点模板
出口在这里:

{{outlet}}
这应该呈现一个
节点/索引
节点/模板1
模板,具体取决于路由。这确实发生了,但模板只是显示空数据。为什么呢


(如
节点
表模板中所示,数据很好)

节点/索引
节点
的隐式子路由。它没有
NodeRoute
中提供的模型。您需要使用
needs
NodeIndexController
中查找值

  App.NodeIndexController = Ember.ObjectController.extend({
      needs: 'node',
      contentBinding: 'controllers.node'
  });

更新。

节点/索引
节点
的隐式子路由。它没有
NodeRoute
中提供的模型。您需要使用
needs
NodeIndexController
中查找值

  App.NodeIndexController = Ember.ObjectController.extend({
      needs: 'node',
      contentBinding: 'controllers.node'
  });

更新。

您需要声明节点/索引和节点/模板1的路由,然后实现model函数,以便它从节点资源中检索模型,因为节点资源就是放置动态段的位置

例如:

App.NodeTemplate1Route = Ember.Route.extend({
  model: function() {
    return this.modelFor('node');
  }
});

App.NodeIndexRoute = Ember.Route.extend({
  model: function() {
    return this.modelFor('node');
  }
});

您可以看到它在这个版本的fiddle中工作:

您需要声明节点/索引和节点/模板1的路由,然后实现model函数,以便它从节点资源检索模型,因为节点资源就是放置动态段的地方

例如:

App.NodeTemplate1Route = Ember.Route.extend({
  model: function() {
    return this.modelFor('node');
  }
});

App.NodeIndexRoute = Ember.Route.extend({
  model: function() {
    return this.modelFor('node');
  }
});
您可以看到它在这个版本的小提琴中工作: