【问题标题】:Add a static element to a CollectionView将静态元素添加到 CollectionView
【发布时间】:2013-01-13 20:37:30
【问题描述】:

是否可以让 CollectionView 呈现 <ul> 容器,其项目为 <li>,并在最后插入静态 <li> 项目?我们正在迭代一个呈现为链接的对象数组,并希望在列表末尾插入一个“新”链接。

【问题讨论】:

    标签: ember.js


    【解决方案1】:
    MyApp.TheView = Ember.CollectionView.extend({
      content: [1, 2, 3, 4],
      tagName: 'ul',
      itemViewClass: Ember.View.extend({
        tagName: 'li',
        template: Ember.Handlebars.compile("{{view.content}}")
      }),
      didInsertElement: function() {
        this.pushObject(Ember.View.create({
          tagName: 'li',
          template: Em.Handlebars.compile("<button>NEW</button>")
        }));
      }
    })
    

    这应该会有所帮助...

    【讨论】:

    • 这是不可能的。现在有什么想法吗?
    • @OscarVGG 你能发个小提琴让我更新吗,需要看看为什么现在不起作用
    • 只需添加一件事。 this.get('childViews').pushObject(... 应替换为 this.pushObject(...,因为不推荐直接操作“childViews”
    猜你喜欢
    • 1970-01-01
    • 2016-07-08
    • 2018-06-01
    • 2021-06-15
    • 1970-01-01
    • 2016-02-09
    • 2014-04-13
    • 2017-09-26
    • 1970-01-01
    相关资源
    最近更新 更多