appcelerator workaround for ti.include not working

假装没事ソ 提交于 2019-12-08 11:43:01

问题


Hi I have tried the workaround suggested by the appcelerator team (for dealing with the deprecation of ti.include in version 6.0.0)

function include(file) {
    return eval(Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory, file).read().text); 
}

And I get an error, probably the system can't read the file. the error is:

[ERROR] : TiBlob: java.io.FileNotFoundException: Resources/underscore-min.js

I have managed to list the directory files through .getDirectoryListing() and couldn't find the file, actually I couldn't find any .js file there.

Any suggestions?


回答1:


Short answer: Don't try to use the workaround but migrate your apps to the correct require functionality. The Ti.include() method has been deprecated since 3.3.0 (!) and has been removed in 6.0.0 (3 major versions later). All current and future apps use this behavior for scalable high-performance apps and so should you.

For your use-case, this is how you would use your library nowadays:

var _ = require('underscore-min')

It expects your file to be placed in <project-root>/Resources/underscore-min.js (Classic projects) or <project-root>/app/lib/underscore-min.js (Alloy projects).

Read more about require and how to use it here and here.

Code strong! 🚀



来源:https://stackoverflow.com/questions/41133082/appcelerator-workaround-for-ti-include-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!