Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 主干网中的路径操作_Javascript_Backbone.js_Coffeescript_Filepath - Fatal编程技术网

Javascript 主干网中的路径操作

Javascript 主干网中的路径操作,javascript,backbone.js,coffeescript,filepath,Javascript,Backbone.js,Coffeescript,Filepath,目前,我在数组中有一些视图路径,这是必需的,但我想自动扫描目录和子目录中的文件夹: paths = ['a/', 'b/', 'c/', 'd/d2/', ''] for path in paths try View = require(path+name) catch e lastError = e if View return View else throw lastError 我尝试了以下操作,但似乎无法使用File类: p

目前,我在数组中有一些视图路径,这是必需的,但我想自动扫描目录和子目录中的文件夹:

paths = ['a/', 'b/', 'c/', 'd/d2/', '']
for path in paths
    try
        View = require(path+name)
    catch e
        lastError = e
if View
    return View
else
    throw lastError
我尝试了以下操作,但似乎无法使用File类:

paths = []
clientPath = __dirname.replace('/base', '') # go up a directory
currentFiles = []
currentFiles = fs.readdirSync(clientPath)
for file in currentFiles
    checkFile = new File(clientPath + "/" + file).isDirectory()
    if checkFile
        paths.push(file + "/")

操作主干中的路径字符串的好方法是什么?

如果此代码在浏览器中运行,那么您就倒霉了。出于安全原因,JavaScript在浏览器中运行,因此您不能以这种方式要求文件

好消息是。您也可以使用类似于的方法来完成此构建步骤