0
我获得存储在$(“#预算”)一个JSON可变数据(“分配”)通过变量访问属性时出现语法错误?
我可以访问它的数据是这样的:
id = "5";
alert($("#budget").data('allocations')[id].amount);
但我需要访问它像这样:
var id = "5";
var field = "amount";
alert($("#budget").data('allocations')[id].[field]);
在属性名称中使用变量会导致失败。
以后缺少名字。运营商(指[字段])
噢很好,我唯一的问题是这个时期。 $(“#budget”)。data('allocations')[id]。[field] should be $(“#budget”)。data('allocations')[id] [field]谢谢! – 2bytes 2012-03-10 21:26:20
@ 2bytes:就这样,说谢谢接受答案,谢谢:) – pimvdb 2012-03-10 22:39:07