![](/img/trans.png)
[英]How do I get the current value of a button being called from an array to display something from another array?
[英]How to get a value from $.something{(...)}
我有以下代码:
$.simpleWeather({
location: coordinates,
unit: 'c'
}
我想获得“单位”的价值。 我如何得到它? 我试过这个:
console.log($.simpleWeather.unit);
但它返回“未定义”。
另外,因为我不知道如何称呼它,所以我也不能简单地谷歌它......
这完全取决于simpleWeather
对您放入其中的对象的处理方式。 从表面上看,simpleWeather 是一个 jquery 扩展。 您可以将它们视为接受参数的函数,并且可能(也可能不会)返回一个 jquery 选择器。
如果 simpleWeather 返回一个 jquery 本身而不是一个裸 jquery 选择器(或者根本没有),你可以这样做:
var sw = $.simpleWeather({
location: coordinates,
unit: 'c'
}
console.log(sw.unit);
您可能想尝试这样做,只是为了弄清楚 jquery 扩展的返回值中的实际内容。
var sw = $.simpleWeather({
location: coordinates,
unit: 'c'
}
console.log(sw);
如果无法从扩展的返回值中检索单元,您可能需要单独跟踪它。 如果有多个实例,您可以使用数组执行此操作,如下所示:
var swInstances = [];
...
var swParameters = {
unit : 'c',
location : coordinates,
};
swInstances.push({
usedParameters : swParameters,
simpleWeatherInstance : $.simpleWeather(swParameters)
});
然后,您可以使用 swInstances 数组访问每个 simpleWeather 实例所需的所有信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.