eBay JavaScript API - @ symbol in object member name
I am using the eBay JavaScript Finding API. The currency id member of the findItemsAdvancedRespon开发者_如何学编程se
object is defined as @currencyId
. So I am retrieving this value as:
function _cb_findItemsAdvanced(root) {
var items = root.findItemsAdvancedResponse[0].searchResult[0].item || [];
var html = [];
if (items.length == 0) {
html.push('No Results');
}
for (var i = 0; i < items.length; ++i) {
var item = items[i];
var title = item.title;
var pic = item.galleryURL;
var viewitem = item.viewItemURL;
var price = Number(item.sellingStatus[0].currentPrice[0].`__value__`).toFixed(2);
var currency = ""
var currency = item.sellingStatus[0].currentPrice[0].@currencyId;
if (null != title && null != viewitem) {
html.push('<div class="item-layout5"><table><tr><td><div style="width:102px;overflow:hidden;">');
html.push('<a href="' + viewitem + '" target="_blank" rel="nofollow"><img src="' + pic + '" border= "" alt="' + title + '" /></a></div></td>');
html.push('<td><span class="itemname"><a href="' + viewitem + '">' + title + '</a></span></td></tr>');
html.push('<tr><td><img src="PTMFOG0000000064.gif" alt="" /></td><td><span class="buyprice">' + currency + ' $' + price + '</span></td></tr></table></div>');
}
}
document.getElementById("results").innerHTML = html.join("");
} // End _cb_findItemsByKeywords() function
This works fine for Firefox browsers, but not for Google Chrome or IE (I get a compilation error).
Is using the @ symbol in a member name acceptable in JavaScript? And what workaround can I use so that the above code will work in all browsers?
Thanks
In javascript, the syntax
foo.bar
is equivalent to
foo['bar']
and the latter works even when 'bar' is not a valid identifier name, as in this case.
精彩评论