admin管理员组

文章数量:1394228

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.

本文标签: javascriptSet propertyattribute in a ExtJS componentStack Overflow