首页 \ 问答 \ 在移动到服务器主机之前,如何处理代码中的文件路径?(How do I handle file paths in my code before moving to server host?)

在移动到服务器主机之前,如何处理代码中的文件路径?(How do I handle file paths in my code before moving to server host?)

在我的网页中,我引用了js和图像,如下所示:“../../Content/Images/”文件名“

在我的代码中,如果我参考上面的文件,它不起作用,所以我必须写:“c:/ miscfiles /”filename“

1-为什么第一个参考在网页上工作,而不在代码中? 2 - 我应该如何在代码中引用文件路径,以便在移动到服务器时不必重新编码?


In my webpages I have references to js and images as such: "../../Content/Images/"Filename"

In my code if I reference a file as above, it doesnt work so i have to write: "c:/miscfiles/"filename"

1-Why does the first reference work on webpages and not within the code? 2-How should i reference file paths in code so that I will not have to recode when moving to server?


原文:https://stackoverflow.com/questions/1727320
更新时间:2022-02-20 09:02

最满意答案

感谢JSBob与我合作。 我有它的工作:

function updateGraphs(newData){

d3.selectAll("svg").each(function(d, i){

    eachRace = d.values;
    svg = d3.select(this);
    yMax = d3.max(eachRace, function(d) { return d[newData]; });
    yScale = d3.scale.linear().domain([0, yMax*1.25]).range([height/8, 0]).nice();
    yAxis = d3.svg.axis().scale(yScale).orient("left").ticks(5);
    console.log(yMax);
    line = d3.svg.line()
    .x(function (d) { return x(d.date); })
    .y(function (d) { return yScale(d[newData]); })

    svg.transition().duration(1000).select(".line")
    .attr("id", function(d) { return d.key ;})
    .attr('class', 'line')
    .attr('opacity', .8)
    .attr('d', function(d) { return line(d.values); });

    svg.transition().duration(1000).select(".y.axis")
    .call(yAxis);

});
}

Thanks JSBob for working with me. I've got it working with:

function updateGraphs(newData) {

d3.selectAll("svg").each(function(d, i){

    eachRace = d.values;
    svg = d3.select(this);
    yMax = d3.max(eachRace, function(d) { return d[newData]; });
    yScale = d3.scale.linear().domain([0, yMax*1.25]).range([height/8, 0]).nice();
    yAxis = d3.svg.axis().scale(yScale).orient("left").ticks(5);
    console.log(yMax);
    line = d3.svg.line()
    .x(function (d) { return x(d.date); })
    .y(function (d) { return yScale(d[newData]); })

    svg.transition().duration(1000).select(".line")
    .attr("id", function(d) { return d.key ;})
    .attr('class', 'line')
    .attr('opacity', .8)
    .attr('d', function(d) { return line(d.values); });

    svg.transition().duration(1000).select(".y.axis")
    .call(yAxis);

});
}

相关问答

更多
  • 感谢NoahRC给了我一个解决方案。 第一个代码块应该在循环之前定义“i”的函数: var tween = function(i){ arcs.transition() .delay((slideDuration + spinDuration) * i) .duration(spinDuration) .ease("cubic-out") .attrTween("transform", function (){ return d3.interpolateString("rota ...
  • 你需要在你传递给d3.json但不在它之外的回调函数(错误,图形)中设置svg 原因:您传递给d3.json的回调函数是异步调用的,即当您循环遍历eventss数组时,每次迭代它将无法正常运行。 在循环结束后,似乎所有4个回调都返回,因此svg被设置为它在该循环中的最后一个值,因此所有内容都被添加到该svg元素中。 You need to set svg within the callback function(error, graph) you pass to d3.json and not outsid ...
  • 我认为快速平滑动画的最佳选择是放弃过渡并使用window.requestAnimationFrame 。 我认为它看起来像这样: function tick() { data[current_i] = get_next_data_point(); current_i = (current_i + 1) % window_width_in_samples; path.data(data).attr("d", line); window.requestAnimationFr ...
  • 在arcTween返回arc(d)时: function arcTween(transition, newAngle) { transition.attrTween("name", function(d) { var interpolate = d3.interpolate(d.endAngle, newAngle); return function(t) { d.endAngle = interpolate(t); ...
  • 您的脚本都声明了名为'svg'的全局变量,然后在加载文件后在回调中引用此全局变量。 如果检查图形,您将看到它们实际上都在同一个SVG元素上,而线图应该在的SVG元素是空的。 您需要在第二个脚本中重命名变量,以使它们的名称与第一个脚本中的变量不同。 Both your scripts declare global variables named 'svg' and then reference this global variable in the callback after the file is loa ...
  • 感谢JSBob与我合作。 我有它的工作: function updateGraphs(newData){ d3.selectAll("svg").each(function(d, i){ eachRace = d.values; svg = d3.select(this); yMax = d3.max(eachRace, function(d) { return d[newData]; }); yScale = d3.scale.linear().domain([0, yM ...
  • 这个片段有问题: data.forEach(function (d) { d.date = parseTime(d.date); d.units = parseInt(d.units); }); tdata.forEach(function (d) { d.date = parseTime(d.date); d.units = parseInt(d.units); }); tdata和data是包含对相同对象的引用的数组。 所以第二个forEach然后作用于相同的对象并且parseTime ...
  • 那么你在我之前的答案中发现了一个错误:) 正如您所说,问题是保存的值未正确更新。 那是因为回调内部不再引用path DOM元素。 修复很简单 - 在上面的级别的函数中保存this的引用并使用该引用: function arcTweenUpdate(a) { var i = d3.interpolate({x: this.x0, dx: this.dx0}, a); var that = this; return function(t) { var b = i(t); that.x ...
  • 因此,转换多个属性是这个问题的简单部分。 就像常规选择一样,您可以在转换时一次设置多个属性: selectedNodeCircles.transition().duration(500) .attr("r", function(d){ return rRange(d.rSize); }) .attr("stroke", 'red'); 这将转换您的半径和线条颜色。 转换是DOM元素的属性(在本例中为圆圈),它将根据您的喜好转换尽可能多的DOM属性。 要记住的是每个DOM元素上只有一个转换对 ...
  • 滞后可以很容易地解释。 你忘了改变这个: for (var i = 0; i < dataSet.length; ++i) simulation.tick(); 在我的原始代码中,我有大约190个国家。 但是,您有440个数据点,这需要更多时间进行计算。 因此,只需将tick的调用次数更改为100到300之间的值: for (var i = 0; i < 150; ++i) simulation.tick(); // ^-------- tweak this numbe ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)