How to Set Dynamic Value in My Attribute

How to Dynamically set the attributes of a component, from users input?

You can achieve it by passing all attributes you want as props to the child component.

You should also add them to state of parent component with change handler.

Each time the user change something of the attributes, the state should update.

As the state updates, the new state will pass as props to child Component and it'll update.

I made a simple example to input: You can change its placeholder, minLength, and requierd.

Check This Example

How to get a dynamic attribute value

Change your jQuery function like this:

$("#parent li a").click(function(){

var id = $(this).attr('id'); // use `this`

alert(id);
});

Note
The code you have used var id = $('#parent li a').attr('id'); will always consider the 1st <a> of the 1st <li> which was wrong.

this will refer to the element which was clicked. Hence you would get the correct value.

Assigning a variable value to an attribute in a dynamic html table

I got it.I can do something like this :

'<td nowrap><input type="checkbox" align="center" style="cursor: hand" name="selectIssue" dummy='+dummyVar+'> </td>'

Dynamically assign a variable value to a html attribute

You can do it via attribute binding, just like you bind properties and events, the syntax for attribute binding is:

[attr.<attribute_name>]="value"
[attr.data-target]="action.dataModalTarget"

Reference: Angular doumentation

How to set dynamic value in my Attribute

You could create an enum with special values, and accept them in a separate constructor overload in the attribute:

enum SpecialConfigurationValues
{
MachineName
// , other special ones
}

class ConfigurationKeyAttribute : Attribute
{
private string _key;
private string _value;

public ConfigurationKeyAttribute(string key, string value)
{
// ...
}

public ConfigurationKeyAttribute(string key, SpecialConfigurationValues specialValue)
{
_key = key;
switch (specialValue)
{
case SpecialConfigurationValues.MachineName:
_value = Environment.MachineName;
break;
// case <other special ones>
}
}
}

[ConfigurationKey("MonitoringService", SpecialConfigurationValues.MachineName)]

Dynamically add attribute and set value based on parent dynamic attribute

With XSLT 2.0 you can use

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">

<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>

<xsl:template match="*[not(self::newline or self::tab or self::space)]">
<xsl:param name="test" tunnel="yes" select="''"/>
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsl:attribute name="test" select="$test"/>
<xsl:apply-templates select="node()">
<xsl:with-param name="test" tunnel="yes" select="concat($test, 'f')"/>
</xsl:apply-templates>
</xsl:copy>

</xsl:template>
</xsl:transform>

with XSLT 1.0 you need to make sure the identity transformation template (the first template) and all other templates you might have pass on the parameter as well:

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

<xsl:template match="@*|node()">
<xsl:param name="test"/>
<xsl:copy>
<xsl:apply-templates select="@*|node()">
<xsl:with-param name="test" select="concat($test, 'f')"/>
</xsl:apply-templates>
</xsl:copy>
</xsl:template>

<xsl:template match="*[not(self::newline or self::tab or self::space)]">
<xsl:param name="test" select="''"/>
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsl:attribute name="test">
<xsl:value-of select="$test"/>
</xsl:attribute>
<xsl:apply-templates select="node()">
<xsl:with-param name="test" select="concat($test, 'f')"/>
</xsl:apply-templates>
</xsl:copy>

</xsl:template>
</xsl:transform>

Two dynamic select boxes with data attribute in both and dependant on them

Since you're using jQuery, you might as well use it all the way.

To make it consistent, always use the jQuery data() method. data() will always try to intelligently convert the value of the data field to another type if it can determine that it is a number, or an object, or an array, or etc. So your original was comparing a dataset.option to a data(), using === which removes type coersion. So nothing would ever be equal.

var sel1 = $('#hours');var sel2 = $('#paxno');var options2 = sel2.find('option');
function giveSelection() { var target = sel1.find(':selected').data('option'); sel2.empty().append( options2.filter(function(){ return $(this).data('option') === target; }) );}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script><select id="hours" onchange="giveSelection()">  <option value="somethingA" data-option="1">optionA</option>  <option value="somethingB" data-option="2">optionB</option></select><select id="paxno">  <option data-option="1">optionC</option>  <option data-option="1">optionD</option>  <option data-option="2">optionE</option>  <option data-option="1">optionF</option></select>


Related Topics



Leave a reply



Submit