如何添加和使用Cordova插件(How to add and work with Cordova plugins)
我如何在我的Cordova应用程序中添加插件? 我找不到任何例子。 我正在尝试在nodejs提示符下安装和添加插件:
npm i PLUGIN_NAME
和cordova plugin add PLUGIN_NAME
。 之后,我正在尝试在标签<script></script>
index.html
文件中为此插件编写代码,并且我在控制台中有很多错误:Uncaught ReferenceError: cordova is not defined(…)
或另一个。 我读过许多关于这个的文档,我知道我需要将任何有关插件的记录添加到config.xml文件中。 但我怎么能做到这一点? 你能帮我解决这个问题吗?How I can add plugins in my Cordova app? I can't find any examples. I'm trying to install and add plugins in nodejs prompt:
npm i PLUGIN_NAME
andcordova plugin add PLUGIN_NAME
. After that, I'm trying to write a code for this plugin in myindex.html
file in tag<script></script>
and I have many errors in console like that:Uncaught ReferenceError: cordova is not defined(…)
or another. I did read many documentation about that and I know that I need to add any records about plugins to config.xml file. But how I can do it? Can you help me with this trouble?
原文:https://stackoverflow.com/questions/40647460
最满意答案
Node.js是事件驱动的,这意味着大部分函数是异步的。
execute
函数不会返回任何值,因为“返回”值位于声明为第一个参数的匿名函数中,只有在查询已执行并且数据库已返回值时才会调用该函数。 所以你的result
变量不包含任何值,因为没有任何东西可以返回。** 编辑 **
即使在编辑之后,记录变量
result
rows
也会在向其分配rows
之前执行,因为匿名函数仅在稍后执行,即查询完成时。Node.js is event driven, meaning that most of the functions are asynchronous. The
execute
function does not return any value, because the "returned" value is in the anonymous function declared as your first argument, which function will be called only when the query has been executed and a value has been returned by the database. So yourresult
variable does not contain any value, because there's nothing to return yet.** EDIT **
Even after your edit, the line where you log the variable
result
is executed before you assignrows
to it, because the anonymous function is only executed later, when the query is completed.
相关问答
更多-
你将fridge作为参数传递,如果它将成为局部变量。 要使用全球fridge你应该这样做: FRIDGE = {"cheese": 10, "milk": 11, "feta": 12, "cream": 21, "onion": 32, "pepper": 25} def fridge_function(): del FRIDGE["feta"] fridge_function() # you need to call it print(FRIDGE) 全局变量通常是上层变量,所以我称之 ...
-
匿名函数范围混淆(Anonymous function scope confusion)[2023-03-12]
Node.js是事件驱动的,这意味着大部分函数是异步的。 execute函数不会返回任何值,因为“返回”值位于声明为第一个参数的匿名函数中,只有在查询已执行并且数据库已返回值时才会调用该函数。 所以你的result变量不包含任何值,因为没有任何东西可以返回。 ** 编辑 ** 即使在编辑之后,记录变量result rows也会在向其分配rows 之前执行,因为匿名函数仅在稍后执行,即查询完成时。 Node.js is event driven, meaning that most of the functi ... -
假设 global $this_month_revenue; global $this_month_sales; global $last_month_revenue; global $last_month_sales; 是您在调用它时要传递给函数的变量。 例如: compareMonths($checkingRevenue, $this_month_revenue, $this_month_sales); function compareMonths($checkingRevenue, $val1, ...
-
匿名函数的范围(Scope on anonymous function)[2022-04-17]
您可以使用“use”来使用父作用域中的变量: $this->getRouter()->addRoute($routing->getPath(), function() use ($routing) { // SCOPE PROBLEM: $routing is no more available if($routing->hasController()) { // Line 60 Controller::get($routing->getController(), $this ... -
这只是JavaScript的核心概念(特别是ECMAScript5)。 匿名函数,特别是在闭包中,不保留上下文。 你可以做这样的事情: (function() { console.log("inner func: this.foo = " + this.foo); console.log("inner func: self.foo = " + self.foo); }).call(this); 那是因为你实际上在调用这个函数。 如果您传递回调,则可以使用Function.prototy ...
-
C ++与新的和范围的混淆(C++ confusion with new and scope)[2022-03-06]
它会是对象的副本吗? 是。 或者可以使用移动,或者可以优化整个事物,以便在最终的编译程序中只生成一个实际对象。 但是,基本上,是的。 如果我用一个新的Object替换对象向量中的元素2,那么旧的值现在是“超出范围”并被删除了吗? 是。 顺便说一句,你正在使用不存在的元素; 要添加元素,请使用insert或push_back 。 Will it be a copy of the object? Yes. Or a move could be used instead, or the entire thing ... -
假设此代码的目的只是为了学习; 你创建一个匿名函数,但你仍然指的是前一个范围中的i ,所以你不要改变你最初编写的第一个代码; i仍然有最后一个值( list.length )。 为了避免这种情况,您需要在您创建的函数范围内具有i的当前值: function buildList(list) { var result = []; for (var i = 0; i < list.length; i++) { var item = 'item' + list[i]; result.pus ...
-
它被称为变量范围和阴影: Go是使用块的词法范围: 1 - 预先声明的标识符的范围是Universe块。 2 - 在顶级(在任何函数之外)声明的表示常量,类型,变量或函数(但不是方法)的标识符的范围是包块。 3 - 导入包的包名称范围是包含导入声明的文件的文件块。 4-表示方法接收者,函数参数或结果变量的标识符的范围是函数体。 5-在函数内声明的常量或变量标识符的范围从ConstSpec或VarSpec(短变量声明的ShortVarDecl)结束开始,并在最内层包含块的末尾结束。 6-在函数内声明的类型标识 ...
-
是的:您可以使用“使用”声明。 function a() { $c = 1; b(function() use ($c) { echo $c; }); } function b($code){ $code(); } Yes: you can use "use" statement. function a() { $c = 1; b(function() use ($c) { echo $c; }); } funct ...
-
如果你不想要$this的值,你需要一个静态匿名函数 。 class Foo{ public function bar(){ $data = [ 'calculation' => static function(){ // $this is not defined } ]; } } 静态匿名函数没有自动绑定的$this值,并且以后不能将其他值绑定到它们。 If you don't want a value for $this, ...