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
Javascript 无余烬数据的余烬动态段_Javascript_Ember.js_Ember Data - Fatal编程技术网

Javascript 无余烬数据的余烬动态段

Javascript 无余烬数据的余烬动态段,javascript,ember.js,ember-data,Javascript,Ember.js,Ember Data,我正在为路线的动态部分而挣扎。这是我的密码 App.Router.map(function(){ this.resource('stuff', {path: '/stuff/:stuff_id'}, function() { this.route('make'); this.route('edit'); this.route('delete'); this.route('history

我正在为路线的动态部分而挣扎。这是我的密码

        App.Router.map(function(){
        this.resource('stuff', {path: '/stuff/:stuff_id'}, function() {
          this.route('make');
          this.route('edit');
          this.route('delete');
          this.route('history');
          });
        });

        App.StuffRoute = Ember.Route.extend({
            model: function(param) {
            },
        setupController: function (){
            },
            renderTemplate: function() {
            }
        });

       App.StuffView= Ember.View.extend({
         defaultTemplate: Ember.Handlebars.compile(stuffTemplate)
       });

       App.StuffController = Ember.Controller.extend();

我应该在
StaffRoute
的模型中添加什么内容,使我不再得到
与URL“危机”匹配的任何路径
错误?对于
localhost/#stuff
以及如何正确设置动态段部分?我对ember文档的唯一问题是,所有示例都使用未准备好生产的ember数据,我不想使用它

如果没有ember数据,您通常会将带有jQuery的直接getJSON放在路由的
model
方法中。
model
方法支持承诺,因此可以重用jQuery承诺

例如,给定使用Flickr api为
/images/tag
路由加载图像列表的路由

App.Router.map(function() {
  this.resource('images', { path: '/images/:tag'});
});

App.ImagesRoute = Ember.Route.extend({
  model: function(params) {
    flickerAPI = 'http://api.flickr.com/services/feeds/photos_public.gne?jsoncallback=?';
    console.log('ImagesRoute.model', params);

    return jQuery.getJSON( flickerAPI, {
      tags: params.tag,
      tagmode: 'any',
      format: "json"
    })
    .then(function(data) {
      console.log('loaded images', data);
      return data;
    })
    .then(null, function() { console.log('failed to load images'); });
  }
});
相应的控制器可以自动访问/绑定返回的json的属性。或者,您可以为几个计算属性设置别名

App.ImagesController = Ember.ObjectController.extend({
  images: function() {
    return this.get('model').items;
  }.property('controller'),
  title: function() {
    return this.get('model').title;
  }.property('images')
});
<script type='text/x-handlebars' data-template-name='images'>
<h1>{{title}}</h1>
{{#each image in images}}
  <img {{bindAttr src='image.media.m'}} />
{{/each}}
</script>
然后使用这些属性通过把手进行渲染

App.ImagesController = Ember.ObjectController.extend({
  images: function() {
    return this.get('model').items;
  }.property('controller'),
  title: function() {
    return this.get('model').title;
  }.property('images')
});
<script type='text/x-handlebars' data-template-name='images'>
<h1>{{title}}</h1>
{{#each image in images}}
  <img {{bindAttr src='image.media.m'}} />
{{/each}}
</script>

{{title}}
{{#图像中的每个图像}
{{/每个}}

这里有一个可以做到这一点的方法。

如果没有余烬数据,您通常会将带有jQuery的直接getJSON放在路由的
model
方法中。
model
方法支持承诺,因此可以重用jQuery承诺

例如,给定使用Flickr api为
/images/tag
路由加载图像列表的路由

App.Router.map(function() {
  this.resource('images', { path: '/images/:tag'});
});

App.ImagesRoute = Ember.Route.extend({
  model: function(params) {
    flickerAPI = 'http://api.flickr.com/services/feeds/photos_public.gne?jsoncallback=?';
    console.log('ImagesRoute.model', params);

    return jQuery.getJSON( flickerAPI, {
      tags: params.tag,
      tagmode: 'any',
      format: "json"
    })
    .then(function(data) {
      console.log('loaded images', data);
      return data;
    })
    .then(null, function() { console.log('failed to load images'); });
  }
});
相应的控制器可以自动访问/绑定返回的json的属性。或者,您可以为几个计算属性设置别名

App.ImagesController = Ember.ObjectController.extend({
  images: function() {
    return this.get('model').items;
  }.property('controller'),
  title: function() {
    return this.get('model').title;
  }.property('images')
});
<script type='text/x-handlebars' data-template-name='images'>
<h1>{{title}}</h1>
{{#each image in images}}
  <img {{bindAttr src='image.media.m'}} />
{{/each}}
</script>
然后使用这些属性通过把手进行渲染

App.ImagesController = Ember.ObjectController.extend({
  images: function() {
    return this.get('model').items;
  }.property('controller'),
  title: function() {
    return this.get('model').title;
  }.property('images')
});
<script type='text/x-handlebars' data-template-name='images'>
<h1>{{title}}</h1>
{{#each image in images}}
  <img {{bindAttr src='image.media.m'}} />
{{/each}}
</script>

{{title}}
{{#图像中的每个图像}
{{/每个}}

这里有一个可以执行此操作的方法。

'/stuff/:stuff_id'
只匹配
/stuff/something
,而不匹配
'/stuff'

尝试定义单独的资源:

App.Router.map(function(){
this.resource('stuffs', {path: '/stuff'});
this.resource('stuff', {path: '/stuff/:stuff_id'}, function() {
    // routes ...
});


并对该资源使用
App.StuffsRoute
App.StuffsView
App.StuffsController

'/stuff/:stuff\u id'
只匹配
/stuff/something
,而不匹配
/stuff'

尝试定义单独的资源:

App.Router.map(function(){
this.resource('stuffs', {path: '/stuff'});
this.resource('stuff', {path: '/stuff/:stuff_id'}, function() {
    // routes ...
});

并使用此资源的
App.StuffsRoute
App.StuffsView
App.StuffsController