我正在使用此小部件在我的Titanium Alloy应用程序中显示SVG:
https://github.com/appcelerator-services/VectorImage
SVG显示得很好,但是当我点击iOS上的SVG时,onClick事件不会触发。 Onclick适用于Android。我已经尝试将onClick应用于小部件本身以及将其应用于包含元素。我可以单击包含元素,但不能单击SVG。
<View class="dashboardGridCell" onClick="goToPayBill">
<View class="dashboardIcon">
<Widget class="dashboardIconSvg" src="com.capnajax.vectorimage" svg="svg/circle-check.svg" style="svg/white-fill.css" onClick="goToPayBill"/>
</View>
<Label class="dashboardIconLabel">Pay Bill</Label>
</View>
是否有更好的小部件用于显示SVG,或者我在应用onclick时遇到了什么问题?
答案 0 :(得分:2)
Widget不支持XML中的onClick处理程序,因为它们不是标准的Titanium Proxy对象,它们可以是创建者定义的任何对象。此外,即使指定了onClick属性,我们也不会评估您作为函数传入的onClick参数。
要在窗口小部件上设置点击事件,您需要在javaScript中执行此操作(因此您希望为其提供ID)
在您的XML中将其更改为:
import sqlalchemy
engine = sqlalchemy.create_engine("mssql+pyodbc://serverName/master?driver=SQL Server Native Client 11.0;", connect_args = {'autocommit':True})
engine.execute("CREATE DATABASE databaseName ON (FILENAME='E:\\SQL\\path_to_file.mdf') FOR ATTACH;")
然后在你的javaScript中你应该能够做到这一点(基于我可以看到的小部件源代码)。
$cred = Get-Credential # sql authentication
$context = New-AzureSqlDatabaseServerContext `
-ServerName temp01confuseiosql `
-Credential $cred
$storagecontext = (Get-AzureRmStorageAccount `
-ResourceGroupName testrg `
-Name teststore01).Context
Start-AzureSqlDatabaseExport -SqlConnectionContext $context `
-StorageContext $storagecontext `
-StorageContainerName sql `
-DatabaseName testdb `
-BlobName $blobname
希望这有帮助!
答案 1 :(得分:0)
通过从https://github.com/appcelerator-services/VectorImage修改小部件的源代码,我能够让onclick在iOS上工作。在控制器/ widget.js的第197行,我添加了这一行,它将一个空的onclick监听器应用于包含SVG元素的webview:
// Added empty click listener to allow click events to be passed through
view.addEventListener('click', function() {});
然后在我自己的视图中,我能够对包含元素应用onclick,并且当我点击SVG时onclick现在正确触发。我没有必要在widget元素中添加onclick,而且我没有必要在我的控制器的javascript中应用onclick。
<View class="dashboardGridCell" onClick="goToPayBill">
<View class="dashboardIcon">
<Widget class="dashboardIconSvg" src="com.capnajax.vectorimage" svg="svg/circle-check.svg" style="svg/white-fill.css"/>
</View>
<Label class="dashboardIconLabel">Pay Bill</Label>
</View>
使用第一个答案中的方法通过JavaScript应用onclick不起作用。虽然这个修复程序对我有用,但我愿意接受更好的方法来启动onclick。