View EmberJS:以编程方式将子视图添加到集合视图,而不更改基础内容

View EmberJS:以编程方式将子视图添加到集合视图,而不更改基础内容,view,ember.js,collectionview,ember-controllers,View,Ember.js,Collectionview,Ember Controllers,我的EmberJS应用程序现在让我很困惑。我有一个集合视图,它反过来定义了我在代码中定义的自定义视图的itemViewClass。比如: App.CarouselView = Ember.CollectionView.extend({ itemViewClass: App.SlideView.extend(), }); 这个CarouselView是在一个模板中呈现的,该模板有一个动态片段作为支持(我希望这有意义?)。这些动态段的控制器是一个数组控制器,因为这些动态段的模型是一个集合:

我的EmberJS应用程序现在让我很困惑。我有一个集合视图,它反过来定义了我在代码中定义的自定义视图的itemViewClass。比如:

App.CarouselView = Ember.CollectionView.extend({
    itemViewClass: App.SlideView.extend(),
});
这个CarouselView是在一个模板中呈现的,该模板有一个动态片段作为支持(我希望这有意义?)。这些动态段的控制器是一个数组控制器,因为这些动态段的模型是一个集合:)(更多混淆,请让我知道)

到现在为止,你们都知道我基本上是在一个旋转木马中渲染一堆幻灯片。通过设置属性,可以在collectionView中动态备份这些

contentBinding:'controller' // property set in CarouselView, controller corresponds to SlidesController
混乱现在开始了。我想在现有幻灯片集中添加一张幻灯片。因此,我提供了一个带有操作的按钮:“添加'target='view'

在幻灯片视图中

actions:{
   add: function(){
      var carouselView = this.get('childViews')[0]; 
      // SlidesView has carouselView and another view as it's child, hence this.get('childViews')[0] is carouselView
      var newCard = carouselView.createChildView(App.SlideView.extend());
      carouselView.get('childViews').pushObject(newCard);
   }

}
上面的代码很糟糕,让我很伤心。我想通过一个按钮触发器,以编程方式向我的CarouseView集合添加一个新的SlideView。但显然,Ember建议不应该直接操纵ChildView,而应该更改底层内容。 它在my console.log中声明不推荐使用操纵子视图等

所以本质上我需要在我的SlidesController内容中添加一些内容?但是,我不想在内容中添加内容,这只是一个软添加,即为用户提供幻灯片,以便用户可以选择编辑或添加内容。他总是可以扔掉它。一旦用户决定保存此信息,需要我将新幻灯片持久保存到数据库的硬添加就会出现

actions:{
   add: function(){
      var carouselView = this.get('childViews')[0]; 
      // SlidesView has carouselView and another view as it's child, hence this.get('childViews')[0] is carouselView
      var newCard = carouselView.createChildView(App.SlideView.extend());
      carouselView.get('childViews').pushObject(newCard);
   }

}