【发布时间】:2011-09-28 23:56:37
【问题描述】:
这是我到目前为止所得到的。请阅读代码中的注释。它包含我的问题。
var customer; //global variable
function getCustomerOption(ddId){
$.getJSON("http://localhost:8080/WebApps/DDListJASON?dd="+ddId, function(opts) {
$('>option', dd).remove(); // Remove all the previous option of the drop down
if(opts){
customer = jQuery.parseJSON(opts); //Attempt to parse the JSON Object.
}
});
}
function getFacilityOption(){
//How do I display the value of "customer" here. If I use alert(customer), I got null
}
这是我的 json 对象的外观:{"3":"Stanley Furniture","2":"Shaw","1":"First Quality"}。我最终想要的是,如果我传入密钥3,我想得到Stanley Furniture,如果我传入Stanley Furniture,我得到一个3。因为3 是我的数据库中的customerId 而Stanley Furniture 是customerName。
【问题讨论】:
标签: javascript jquery json jsp