最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Set propertyattribute in a ExtJS component - Stack Overflow

programmeradmin0浏览0评论

Is it possible to set a Ext JS ponent property (visibility, value, ...) to a specific value, smilar to jQuerys [.attr(attributeName, value)][1]?

I'm getting the ponent name, the property/attribute name and the value and have to update the UI. My first solution works with a 'dictionary' (yes, i'm a c# developer) which calls the right method for the given attribute and supports visibility, value, enabled.

var methodMapper = {
  "visibility" : function(p, value) {
    if(value == "true" || value == "on" || value == "1" || value == "visible")
      p.show();
    else
      p.hide();
  },
  "value" : function(p, value) {
     p.setValue(value);
  },
  "enable" : function(p, value) {
    if(value == "true" || value == "on" || value == "1" || value == "visible")
      p.enable();
    else
      p.disable();
  }
};

function receiveMessage(element, property, value) {
  var func = methodMapper[property];
  if(!func) return;
  var p = Ext.getCmp(element); // retrieve ponent
  func(p, value); // set property to value
}

Is there any better solution for setting the property in a ponent? I want to extend the supported properties to width, height, draggable, ... .

Is it possible to set a Ext JS ponent property (visibility, value, ...) to a specific value, smilar to jQuerys [.attr(attributeName, value)][1]?

I'm getting the ponent name, the property/attribute name and the value and have to update the UI. My first solution works with a 'dictionary' (yes, i'm a c# developer) which calls the right method for the given attribute and supports visibility, value, enabled.

var methodMapper = {
  "visibility" : function(p, value) {
    if(value == "true" || value == "on" || value == "1" || value == "visible")
      p.show();
    else
      p.hide();
  },
  "value" : function(p, value) {
     p.setValue(value);
  },
  "enable" : function(p, value) {
    if(value == "true" || value == "on" || value == "1" || value == "visible")
      p.enable();
    else
      p.disable();
  }
};

function receiveMessage(element, property, value) {
  var func = methodMapper[property];
  if(!func) return;
  var p = Ext.getCmp(element); // retrieve ponent
  func(p, value); // set property to value
}

Is there any better solution for setting the property in a ponent? I want to extend the supported properties to width, height, draggable, ... .

Share Improve this question edited Jan 16, 2012 at 11:40 Dr. Rajesh Rolen 14.3k42 gold badges110 silver badges180 bronze badges asked Jan 16, 2012 at 11:33 RobarRobar 1,9712 gold badges31 silver badges61 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 4

@Robar

If you want to work at the attributes of an HTML element, its better that you call getEl() method on your ExtJS ponent (say panel) to get the element associated with the ponent and then you can get/set the attributes like how you do it in jQuery because in some cases you may not be able to map the attribute to a ponent property or method.

发布评论

评论列表(0)

  1. 暂无评论