【问题标题】:Manipulating Paths in Backbone在主干中操作路径
【发布时间】:2014-07-26 19:03:26
【问题描述】:

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

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 + "/")

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

【问题讨论】:

    标签: javascript backbone.js coffeescript filepath


    【解决方案1】:

    如果此代码在浏览器中运行,那么您就不走运了。出于安全原因,JavaScript 在浏览器 doesn't have access to the filesystem 中运行,因此您不能以这种方式要求您的文件。

    好消息是Require.js includes an optimiser that will compile your requirements for you。您也可以使用 GruntRequire.js plugin 之类的东西来完成此构建步骤。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多