我正在尝试开发一个wirecloud 运算符,但我不知道如何在config.xml 中包含一个javascript 库(即jquery),除了main.js 文件。我尝试在 config.xml 中包含 jquery 库,就像 main.js 方式一样,使用不同的 wire:index,但它不起作用。
有没有办法包含第二个 JS 库?
我正在尝试开发一个wirecloud 运算符,但我不知道如何在config.xml 中包含一个javascript 库(即jquery),除了main.js 文件。我尝试在 config.xml 中包含 jquery 库,就像 main.js 方式一样,使用不同的 wire:index,但它不起作用。
有没有办法包含第二个 JS 库?
是的,您可以在运算符中拥有多个 javascript 文件。我认为您的问题与有点奇怪的 RDF 语法有关。不管怎样,下面的代码片段是如何使用 RDF/XML 包含 jquery 和 main.js 文件的示例:
<usdl:utilizedResource>
<usdl:Resource rdf:about="js/jquery.min.js">
<wire:index>0</wire:index>
</usdl:Resource>
</usdl:utilizedResource>
<usdl:utilizedResource>
<usdl:Resource rdf:about="js/main.js">
<wire:index>1</wire:index>
</usdl:Resource>
</usdl:utilizedResource>
或者,如果您在 FIWARE Lab 使用 Mashup 门户,则可以使用 WireCloud 0.7.0 上将提供的新 XML 格式(当前 Mashup 门户正在运行该版本的候选发布版)。这是新格式的示例:
<?xml version='1.0' encoding='UTF-8'?>
<operator xmlns="http://wirecloud.conwet.fi.upm.es/ns/macdescription/1" vendor="CoNWeT" name="ngsi-source" version="3.0">
<details>
<title>NGSI source</title>
<homepage>https://github.com/wirecloud-fiware/ngsi-source</homepage>
<authors>Álvaro Arranz García <aarranz@conwet.com></authors>
<email>aarranz@conwet.com</email>
<image>images/catalogue.png</image>
<description>Retrieve Orion Context Broker entities and their updates in real time.</description>
<longdescription>DESCRIPTION.md</longdescription>
<license>AGPLv3+ w/linking exception</license>
<licenseurl>http://www.gnu.org/licenses/agpl-3.0.html</licenseurl>
<doc>doc/userguide.md</doc>
<changelog>doc/changelog.md</changelog>
</details>
<requirements>
<feature name="NGSI"/>
</requirements>
<preferences>
<preference name="ngsi_server" type="text" label="NGSI server URL" description="URL of the Orion Context Broker to use for retrieving entity information" default="http://orion.lab.fi-ware.org:10026/"/>
<preference name="ngsi_proxy" type="text" label="NGSI proxy URL" description="URL of the Orion Context Broker proxy to use for receiving notifications about changes" default="http://mashup.lab.fi-ware.org:3000/"/>
<preference name="ngsi_entities" type="text" label="NGSI entity types" description="A comma separated list of entity types to use for filtering entities from the Orion Context broker. Thies field cannot be empty." default="Node, AMMS, Regulator"/>
<preference name="ngsi_id_filter" type="text" label="Id pattern" description="Id pattern for filtering entities. This preference can be empty, in that case, entities won't be filtered by id." default=""/>
<preference name="ngsi_update_attributes" type="text" label="Monitored NGSI Attributes" description="Attributes to monitor for updates. Currently, the Orion Context Broker requires a list of attributes to monitor for changes, so this field cannot be empty." default="Latitud, Longitud, presence, batteryCharge, illuminance, ActivePower, ReactivePower, electricPotential, electricalCurrent"/>
</preferences>
<wiring>
<outputendpoint name="entityOutput" type="text" label="Provide entity" description="Every change over each entity fires an event" friendcode="entity"/>
</wiring>
<scripts>
<script src="js/other.dependency.js"/>
<script src="js/main.js"/>
</scripts>
</operator>
您可以在此链接中找到有关这种新格式的更多文档。
最后,我开始在wirecloud 运算符上包含其他使用RDF/XML 的JS 文件。首先,我在 config.xml 文件中使用以下代码:
<usdl-core:utilizedResource rdf:about="js/jquery-1.10.2.min.js">
<wire:index>0</wire:index>
</usdl-core:utilizedResource>
<usdl-core:utilizedResource rdf:about="js/main.js">
<wire:index>1</wire:index>
</usdl-core:utilizedResource>
此外,包含的 JS 文件必须声明如下:
<wire:Operator rdf:about="http://wirecloud.conwet.fi.upm.es/ns/widget#Operator">
...
<usdl-core:utilizedResource rdf:resource="js/jquery-1.10.2.min.js"/>
<usdl-core:utilizedResource rdf:resource="js/main.js"/>
....
</wire:Operator>