简体   繁体   English

从Ember视图中删除类名

[英]Removing Classnames from Ember view

I am trying to create view that has functionality described in a view in am extending, but with different class names. 我正在尝试创建具有在扩展视图中描述的功能的视图,但是具有不同的类名。 What is happening is the ExpTypesView classes are ['nav','nav-pills'] and ['nav','nav-tabs']. 发生的是ExpTypesView类是['nav','nav-pills'] ['nav','nav-tabs']。 How do i set it so they replace the classnames set in NavView? 我如何设置它以便它们替换在NavView中设置的类名?

Resume.NavView = Em.View.extend({
  tagName: 'ul',
  classNames: ['nav','nav-tabs'],
  currentPathDidChange: function(){
    Ember.run.next( this, function() {
      $("ul li:has(>a.active)").addClass('active');
      $("ul li:not(:has(>a.active))").removeClass('active');
   }); 
  }.observes('controller.currentPath')
});
Resume.ExpTypesView = Resume.NavView.extend({
  classNames:['nav','nav-pills']
});

In an Ember.View , classNames is a concatenated property so properties that you add will be concatenated with the super class values. Ember.ViewclassNames是一个连接的属性,因此您添加的属性将与超类值连接。

You can use classNameBindings to set the type in both the super class and the descendant. 您可以使用classNameBindings在超类和后代中设置类型。

App.NavView = Em.View.extend({
  tagName: 'ul',
  classNames: ['nav'],
  classNameBindings: ['type'],
  type: 'nav-tabs',
  currentPathDidChange: function(){
    Ember.run.next( this, function() {
      $("ul li:has(>a.active)").addClass('active');
      $("ul li:not(:has(>a.active))").removeClass('active');
   }); 
  }.observes('controller.currentPath')
});

App.ExpTypesView = App.NavView.extend({
  type: 'nav-pills',
});

This makes the classes class="ember-view nav nav-tabs" and class="ember-view nav nav-pills" . 这使得类为class="ember-view nav nav-tabs"class="ember-view nav nav-pills"

JSBin example JSBin示例

This dirty little workaround is giving me what I want, but if you know a better way or any resource that explains this please let me know! 这个肮脏的小解决方法可以满足我的需求,但是如果您知道更好的方法或任何能解释这个问题的资源,请告诉我!

Resume.ExpTypesView = Resume.NavView.extend({
  //classNames:['nav','nav-pills'],
  init: function(){
    this.set('classNames', ['nav','nav-pills']);
  }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM