Original code from JamieMThomas, a (really good guy who is trying to combine Microsoft JQuery Templates and Linking) :
mapping[binding.field] = {
convert: function (value, source, target) {
if (binding.converter && binding.converter.convert) {
value = binding.converter.convert(value, source, target)
if (value === undefined)
return;
}
$(target).attr(attrName, value);
}
};
I am trying to hack it to allow binding.field to work with a string like "LPC[0].itemid" (literally a string). I am using eval as a terrible choice, but it’s the fastest thing I can do (and will rewrite it later). I originally tried assigning the content to the eval(”) itself, but it didn’t allow me.
eval('(mapping.' + binding.field + ')') =
{ // rest is the same
convert: function (value, source, target) {
if (binding.converter && binding.converter.convert) {
value = binding.converter.convert(value, source, target)
if (value === undefined)
return;
}
$(target).attr(attrName, value);
}
};
Obviously an invalid assignment on the left hand side. How could I accomplish this?
You can put the entire assignment in the
eval:This would be a very large string containing the function definition
To make the string smaller, you can put the function in an external variable: