- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我有以下 json:
var data = [
{
"name": "wiredep",
"version": "4.0.0",
"link": "https://github.com/taptapship/wiredep",
"licensePath": "/licenses/wiredep"
}
];
现在我使用以下代码在 html 页面上呈现它:
var transform = {"<>":"li","html":[
{"<>":"span class='name'","html": [{ "<>":"a", "href": " ${link}", "html": " ${name}"}]},
{"<>":"span class='vers'", "html":" ${version}"},
{"<>":"div","html":" ${licensePath}"}
]};
$(function(){
// Create the list
$('#list').json2html(data,transform);
});
在 /licenses/wiredep
中是包含许可信息的文本。我希望能够在 HTML 页面内呈现它。因此,我不想显示 licensepath
本身,而是希望显示该文件中的文本?
所以最终的输出是:
Name: wiredep
Version: 4.0.0
License Path content:
The MIT License (MIT)
Copyright (c) 2014 Stephen Sawchuk
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
最佳答案
JSON2HTML 不知道如何处理文件路径。如果您希望文件的内容包含在输出中,您需要自己将其添加到 data
before 将其传递给 json2html()
.
所以问题变成了“我如何在 javascript 中从文件的路径中获取文件的文本?”,答案并不像您预期的那么复杂。由于您已经在使用 jQuery,我将提供一个使用 jQuery.get()
的解决方案,但这当然也可以在不使用 jQuery 的情况下实现。
这个过程有两个部分:首先您必须发起到服务器的请求,告诉它您想要一个文件的内容。这是使用前面提到的 jQuery.get()
完成的:
$.get('/licenses/wiredep');
就是这样!现在是第二部分:您必须等待服务器响应您请求的文件。我们通过将回调函数绑定(bind)到请求来做到这一点。有几种可供您使用,它们在不同情况下被调用。在这种情况下,为简单起见,我们将忽略任何错误,只关注服务器响应正常的情况。在这种情况下,.done()
回调将被触发:
$.get('/licenses/wiredep').done(function(data) {
console.log('Contents of /licenses/wiredep:', data);
});
Note: This callback is executed asynchronously. This means any code outside of the callback function is not guaranteed to be executed after the request is complete, even if it comes after the request.
现在将这一切与您的代码联系在一起。我故意忽略了 data
是一个可能包含多个对象的数组这一事实。
$.get('/licenses/wiredep').done(function(response) {
var data = [
{
"name": "wiredep",
"version": "4.0.0",
"link": "https://github.com/taptapship/wiredep",
"licensePath": response
}
];
var transform = {"<>":"li","html":[
{"<>":"span class='name'","html": [{ "<>":"a", "href": " ${link}", "html": " ${name}"}]},
{"<>":"span class='vers'", "html":" ${version}"},
{"<>":"div","html":" ${licensePath}"}
]};
$('#list').json2html(data, transform);
});
关于javascript - 如何使用 jQuery 的 json2html 将文件中的文本呈现到另一个 html 页面中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53598701/
表架构 DROP TABLE bla; CREATE TABLE bla (id INTEGER, city INTEGER, year_ INTEGER, month_ INTEGER, val I
我需要拆分字符串/或从具有以下结构的字符串中获取更容易的子字符串。 字符串将来自 window.location.pathname 或 window.location.href,看起来像 text/n
每当将对象添加到数组中时,我都会尝试更新 TextView ,并在 TextView 中显示该文本,如下所示: "object 1" "object 2" 问题是,每次将新对象添加到数组时,它都会覆盖
我目前正在寻找使用 Java 读取网站可见文本并将其存储为纯文本字符串的方法。 换句话说,我想转换成这样: Hello stupid World进入“ Hello World ” 或者类似的东西 Un
我正在尝试以文本和 HTML 格式发送电子邮件,但无法正确发送正确的 header 。特别是,我想设置 Content-Type header ,但我找不到如何为 html 和文本部分单独设置它。 这
我尝试了上面的代码,但我无法绑定(bind)文本,我怎样才能将资源内部文本 bloc
我刚刚完成了 Space Shooter 教程,由于没有 GUIText 对象,所以我创建了 UI.Text 对象并进行了相应的编码。它在统一播放器中有效,但在构建 Web 应用程序后无效。我花了一段
我有这个代码: - (IBAction)setButtonPressed:(id)sender { NSUserDefaults *sharedDefaults = [[NSUserDefau
抱歉标题含糊不清,但我想不出我想在标题中做什么。无论如何,对于图像上的文本,我使用了 JLabel 文本并将其添加到图标中。 JLabel icon = new JLabel(new Imag
关闭。这个问题是not reproducible or was caused by typos .它目前不接受答案。 这个问题是由于错别字或无法再重现的问题引起的。虽然类似的问题可能是on-topi
我在将 Twitter 嵌入到我从 HTML 5 转换的 wordpress 运行网站时遇到问题。 我遇到的问题是推文不是我的自定义字体... 这是我无法使用任何 css 定位的 HTML 代码,我正
我正在尝试找到解决由于使用以下形式的代码而导致的冗余字符串连接问题的最佳方法: logger.debug("Entering loop, arg is: " + arg) // @1 在大多数情况下,
我写了这个测试 @Test public void removeRequestTextFromRouteError() throws Exception { String input = "F
我目前正在创建一个正则表达式来拆分所有匹配以下格式的字符串:&[文本],并且需要获取文本。字符串可能类似于:something &[text] &[text] everything &[text] 等
有没有办法将标题文本从一个词变形为另一个词,同时保留两个词中使用的字母?我看过的许多 css 文本动画大多是视觉的,很少有旋转整个单词的。 我想要做的是从一个词过渡,例如“BEACH”到“CHANGE
总结matplotlib绘图如何设置坐标轴刻度大小和刻度。 上代码: ?
我在容器 (1) 中创建了容器 (2)。你能帮忙如何向容器(1)添加文本吗?下面是我的代码 return Scaffold( body: Padding( padding: c
我似乎找不到任何人或任何人这样做过。我试图限制我们使用的图像数量,并想创建一个带有渐变作为其“颜色”的文本,并在其周围设置渐变轮廓/描边 到目前为止,我还没有看到任何将两者结合在一起的东西。 我可以自
我正在为视频游戏暗黑破坏神 2 使用 discord.py 构建一个不和谐机器人。其中一项功能要求机器人从暗黑破坏神 2 屏幕截图中提取项目的名称和属性。我目前正在为此使用 pytesseract,但
我很难弄清楚如何旋转 strip.text theme 中的属性来自 ggplot2 .我使用的是 R 版本 3.4.2 和 ggplot2 版本 2.2.1。 以下是 MWE 的数据。 > dput
我是一名优秀的程序员,十分优秀!