我有以下内容:
function getPk(entity) {
var store = window.localStorage;
switch (entity) {
case "City":
if (store.getItem('AccountID')) {
// Need to return both of the below pieces of information
return store.getItem('AccountID') + "04" + "000";
return "CityTable";
} else {
paramOnFailure("Please reselect");
return false;
}
break;
问题是我需要能够调用这个函数并返回两个字符串。在这里,我展示了两个返回语句,但我知道我不能那样做。
有没有一种干净的方法可以将两个字符串返回给调用我的 getPk(entity) 函数的函数?
如果可能的话,您能否也举例说明我如何读取返回的内容。
最佳答案
将它们作为数组或对象返回。
return [store.getItem('AccountID') + "04" + "000", "CityTable"];
或
return { accountID: store.getItem('AccountID') + "04" + "000", table: "CityTable" };
关于javascript - 如何从 javascript 函数返回两个参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10561037/