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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.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 具有真实视图而不是虚拟视图的itemController_Ember.js - Fatal编程技术网

Ember.js 具有真实视图而不是虚拟视图的itemController

Ember.js 具有真实视图而不是虚拟视图的itemController,ember.js,Ember.js,我有一个{{{each}}把手助手,有安排的内容,我这样使用它 {{#each arrangedContent itemController='people'}} {{content.name}} {{/each}} App.PeopleItemView = Em.View.extend({ layoutName: 'people_item', }); url: function(){ var pathArray = window.location.href.spli

我有一个{{{each}}把手助手,有安排的内容,我这样使用它

{{#each arrangedContent itemController='people'}}
  {{content.name}}
{{/each}}
App.PeopleItemView = Em.View.extend({
  layoutName: 'people_item',
});
url: function(){
        var pathArray = window.location.href.split('/');
        pathArray.pop();
        var newPathname = "";

        for ( i = 0; i < pathArray.length; i++ ) {
        newPathname += pathArray[i];
        newPathname += "/";
        };
        newPathname+="people/"+this.get('content.id');

        return newPathname;
    }.property('content'),
itemController的功能是为每个项目生成一个虚拟视图

我想,在点击一个内容名称,一个新的窗口应该弹出,可以与视图完成。 但因为我有虚拟视图,所以我无法这样做

我的尝试 我想象的是,如果我创建一个新视图并在{{view App.PeopleItemView的帮助下呈现它,那么它可能会工作

的确如此

{{#each arrangedContent itemController='people'}}
      {{view 'App.PeopleItemView'}}
{{/each}}
我的人员项目视图如下所示

{{#each arrangedContent itemController='people'}}
  {{content.name}}
{{/each}}
App.PeopleItemView = Em.View.extend({
  layoutName: 'people_item',
});
url: function(){
        var pathArray = window.location.href.split('/');
        pathArray.pop();
        var newPathname = "";

        for ( i = 0; i < pathArray.length; i++ ) {
        newPathname += pathArray[i];
        newPathname += "/";
        };
        newPathname+="people/"+this.get('content.id');

        return newPathname;
    }.property('content'),
但它不是这样工作的。我仍然使用虚拟视图

更新 我在peopleController中创建了一个名为url的属性,如下所示

{{#each arrangedContent itemController='people'}}
  {{content.name}}
{{/each}}
App.PeopleItemView = Em.View.extend({
  layoutName: 'people_item',
});
url: function(){
        var pathArray = window.location.href.split('/');
        pathArray.pop();
        var newPathname = "";

        for ( i = 0; i < pathArray.length; i++ ) {
        newPathname += pathArray[i];
        newPathname += "/";
        };
        newPathname+="people/"+this.get('content.id');

        return newPathname;
    }.property('content'),
然后按照@ppcano

的建议访问了它,我认为您弄错了itemController,因为它不应该生成任何内容,而是将项目包装在“内容”中

发件人:

有时,您希望在的主体中显示计算属性 依赖于内容中的基础项的每个帮助程序,但 这些项上不存在。为此,请将itemController设置为 控制器的名称可能是要包装的ObjectController 每个单独的项目

通过使用itemController,项可以具有计算属性等


另一方面,我认为您应该使用View'templateName属性而不是layoutName。请参阅:。

如果我没有错,您的内容显示正确,因此您可以创建html链接,其href值取决于您的个人内容

 {{#each item in model}}
      <a target="_blank" href="{{unbound item.personUrl}}">{{item.name}}</a>
 {{/each}}

如果要重定向到应用程序路由,请使用。目前,它不支持设置目标属性,但a正在进行中。

如果我理解正确,最简单的方法是这样使用:

{{each arrangedContent itemView=item}

这将在arrangedContent中循环,并为每个项目提供App.ItemView的实例

然后,您可以通过视图模板中的{view.content}访问该项


请看一个例子。

新建窗口是什么意思?您想在用户单击人名时显示应用程序弹出窗口还是显示/隐藏个人内容?新建浏览器窗口选项卡此新建选项卡是否链接到您的余烬应用程序或外部网站的URL路径?