- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在制作一个由 wordpress 组成的新闻网站的移动应用程序(使用 ionic 框架)。json 文件是从站点获取的。我必须从 wordpress 网站获取相同的重复 json 数据和一些新帖子,以便我的应用程序在用户继续滚动时显示新消息。所以我必须将这些新的几个帖子对象添加/附加到以前的“帖子”对象数组中。这是常规的 wordpress posts json 文件对象的样子。
{
"status": "ok",
"count": 2,
"count_total": 4231,
"pages": 2116,
"posts": [
{
"id": 62296,
"type": "post",
"slug": "any slug",
"url": "any url",
"status": "publish",
"title": "any title",
"title_plain": "any title",
"content": "any content",
"excerpt": "any excerpt",
"date": "2015-02-26 02:08:57",
"modified": "2015-02-26 02:09:59",
"categories": [
{
"id": 1015,
"slug": "any slug",
"title": "any title",
"description": "",
"parent": 0,
"post_count": 7
}
],
"tags": [
{
"id": 1180,
"slug": "any slug",
"title": "any title",
"description": "",
"post_count": 6
},
{
"id": 1179,
"slug": "religion",
"title": "religion",
"description": "",
"post_count": 5
},
{
"id": 1209,
"slug": "any slug",
"title": "any title",
"description": "",
"post_count": 4
}
],
"author": {
"id": 1,
"slug": "newsdesk",
"name": "NewsDesk",
"first_name": "",
"last_name": "",
"nickname": "NewsDesk",
"url": "",
"description": ""
},
"comments": [],
"attachments": [
{
"id": 44930,
"url": "anything appropriate",
"slug": "anything appropriate",
"title": "anything appropriate",
"description": "",
"caption": "",
"parent": 62296,
"mime_type": "image/jpeg",
"images": {
"full": {
"url": "anything appropriate",
"width": 290,
"height": 147
},
"thumbnail": {
"url": "anything appropriate",
"width": 150,
"height": 147
},
"medium": {
"url": "anything appropriate",
"width": 290,
"height": 147
},
"large": {
"url": "anything appropriate",
"width": 290,
"height": 147
},
"tie-small": {
"url": "anything appropriate",
"width": 55,
"height": 55
},
"tie-medium": {
"url": "anything appropriate",
"width": 272,
"height": 125
},
"tie-large": {
"url": "anything appropriate",
"width": 290,
"height": 147
},
"slider": {
"url": "anything appropriate",
"width": 290,
"height": 147
},
"big-slider": {
"url": "anything appropriate",
"width": 290,
"height": 147
}
}
}
],
"comment_count": 0,
"comment_status": "open",
"thumbnail": "anything appropriate": {
"views": [
"2"
],
"taq_review_button_text": [
""
],
"taq_review_button_size": [
"medium"
],
"taq_review_button_shape": [
"square"
],
"taq_review_button_color": [
"#c7c7c7"
],
"taq_button_icon": [
"fa fa-check"
],
"taq_review_button_type": [
"flat"
],
"taq_review_button_url": [
""
],
"taq_review_title": [
""
],
"taq_review_position": [
""
],
"taq_review_style": [
"stars"
],
"taq_review_summary": [
""
],
"taq_review_total": [
""
],
"tie_hide_meta": [
""
],
"tie_hide_author": [
""
],
"tie_hide_share": [
""
],
"tie_hide_related": [
""
],
"tie_hide_check_also": [
""
],
"tie_sidebar_pos": [
"default"
],
"tie_sidebar_post": [
"category lifestyle"
],
"tie_post_head": [
"none"
],
"tie_post_slider": [
"59602"
],
"tie_googlemap_url": [
""
],
"tie_video_url": [
""
],
"tie_video_self": [
""
],
"tie_embed_code": [
""
],
"tie_audio_m4a": [
""
],
"tie_audio_mp3": [
""
],
"tie_audio_oga": [
""
],
"tie_audio_soundcloud": [
""
],
"tie_banner_above": [
""
],
"tie_banner_below": [
""
],
"tie_posts_num": [
""
],
"post_color": [
""
],
"post_background": [
"anything appropriate"
],
"tie_views": [
"2"
]
},
"thumbnail_size": "thumbnail",
"thumbnail_images": {
"full": {
"url": "anything appropriate",
"width": 290,
"height": 147
},
"thumbnail": {
"url": "anything appropriate",
"width": 150,
"height": 147
},
"medium": {
"url": "anything appropriate",
"width": 290,
"height": 147
},
"large": {
"url": "anything appropriate",
"width": 290,
"height": 147
},
"tie-small": {
"url": "anything appropriate",
"width": 55,
"height": 55
},
"tie-medium": {
"url": "anything appropriate",
"width": 272,
"height": 125
},
"tie-large": {
"url": "anything appropriate",
"width": 290,
"height": 147
},
"slider": {
"url": "anything appropriate",
"width": 290,
"height": 147
},
"big-slider": {
"url": "anything appropriate",
"width": 290,
"height": 147
}
}
},
{
//This is another "posts" object
}
]
}
我对javascript不是很熟悉。因此,将新获取的帖子添加到同一个“帖子”数组中让我感到非常痛苦。
我可以将“posts”数组保存到我的应用程序中的一个变量中。但是不能在最后一个帖子对象之后将新获取的对象追加到“帖子”数组中。
最佳答案
var news = {
"status": "ok",
"count": 2,
"count_total": 4231,
"pages": 2116,
"posts": [{
"id": 62296,
"type": "post",
"slug": "any slug",
"url": "any url",
"status": "publish",
"title": "any title",
"title_plain": "any title",
"content": "any content",
"excerpt": "any excerpt",
"date": "2015-02-26 02:08:57",
"modified": "2015-02-26 02:09:59",
"categories": [{
"id": 1015,
"slug": "any slug",
"title": "any title",
"description": "",
"parent": 0,
"post_count": 7
}],
"tags": [{
"id": 1180,
"slug": "any slug",
"title": "any title",
"description": "",
"post_count": 6
}, {
"id": 1179,
"slug": "religion",
"title": "religion",
"description": "",
"post_count": 5
}, {
"id": 1209,
"slug": "any slug",
"title": "any title",
"description": "",
"post_count": 4
}],
"author": {
"id": 1,
"slug": "newsdesk",
"name": "NewsDesk",
"first_name": "",
"last_name": "",
"nickname": "NewsDesk",
"url": "",
"description": ""
},
"comments": [],
"attachments": [{
"id": 44930,
"url": "anything appropriate",
"slug": "anything appropriate",
"title": "anything appropriate",
"description": "",
"caption": "",
"parent": 62296,
"mime_type": "image/jpeg",
"images": {
"full": {
"url": "anything appropriate",
"width": 290,
"height": 147
},
"thumbnail": {
"url": "anything appropriate",
"width": 150,
"height": 147
},
"medium": {
"url": "anything appropriate",
"width": 290,
"height": 147
},
"large": {
"url": "anything appropriate",
"width": 290,
"height": 147
},
"tie-small": {
"url": "anything appropriate",
"width": 55,
"height": 55
},
"tie-medium": {
"url": "anything appropriate",
"width": 272,
"height": 125
},
"tie-large": {
"url": "anything appropriate",
"width": 290,
"height": 147
},
"slider": {
"url": "anything appropriate",
"width": 290,
"height": 147
},
"big-slider": {
"url": "anything appropriate",
"width": 290,
"height": 147
}
}
}],
"comment_count": 0,
"comment_status": "open",
"thumbnail": "anything",
"appropriate": {
"views": [
"2"
],
"taq_review_button_text": [
""
],
"taq_review_button_size": [
"medium"
],
"taq_review_button_shape": [
"square"
],
"taq_review_button_color": [
"#c7c7c7"
],
"taq_button_icon": [
"fa fa-check"
],
"taq_review_button_type": [
"flat"
],
"taq_review_button_url": [
""
],
"taq_review_title": [
""
],
"taq_review_position": [
""
],
"taq_review_style": [
"stars"
],
"taq_review_summary": [
""
],
"taq_review_total": [
""
],
"tie_hide_meta": [
""
],
"tie_hide_author": [
""
],
"tie_hide_share": [
""
],
"tie_hide_related": [
""
],
"tie_hide_check_also": [
""
],
"tie_sidebar_pos": [
"default"
],
"tie_sidebar_post": [
"category lifestyle"
],
"tie_post_head": [
"none"
],
"tie_post_slider": [
"59602"
],
"tie_googlemap_url": [
""
],
"tie_video_url": [
""
],
"tie_video_self": [
""
],
"tie_embed_code": [
""
],
"tie_audio_m4a": [
""
],
"tie_audio_mp3": [
""
],
"tie_audio_oga": [
""
],
"tie_audio_soundcloud": [
""
],
"tie_banner_above": [
""
],
"tie_banner_below": [
""
],
"tie_posts_num": [
""
],
"post_color": [
""
],
"post_background": [
"anything appropriate"
],
"tie_views": [
"2"
]
},
"thumbnail_size": "thumbnail",
"thumbnail_images": {
"full": {
"url": "anything appropriate",
"width": 290,
"height": 147
},
"thumbnail": {
"url": "anything appropriate",
"width": 150,
"height": 147
},
"medium": {
"url": "anything appropriate",
"width": 290,
"height": 147
},
"large": {
"url": "anything appropriate",
"width": 290,
"height": 147
},
"tie-small": {
"url": "anything appropriate",
"width": 55,
"height": 55
},
"tie-medium": {
"url": "anything appropriate",
"width": 272,
"height": 125
},
"tie-large": {
"url": "anything appropriate",
"width": 290,
"height": 147
},
"slider": {
"url": "anything appropriate",
"width": 290,
"height": 147
},
"big-slider": {
"url": "anything appropriate",
"width": 290,
"height": 147
}
}
}]
}
var newPost = {};
newPost.id = 65869;
newPost.categories = ["a", "b", "c", "d"];
newPost.author = {
"name": "Jimbo",
"last-name": "BobCat"
};
news.posts.push(newPost); //append the new post object.
document.write("<pre>" + JSON.stringify(news) + "</pre>")
为了表达我的意思。我创建了一个新的帖子对象并使用 news.posts.push(newPost)
将其附加。 push
用于将数据附加到数组。
关于javascript - 如何在 Javascript 对象数组的最后一个对象之后附加几个新对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28730516/
我的代码有问题。它总是忽略if(userDigit=1).. 谁能告诉我这里出了什么问题? for(i=0; i=1) { //
我正在尝试从字符串 html_doc 中提取 id=obj1 并尝试将 onclick 函数 附加到它 document.addEventListener("DOMContentLoaded", fu
我正在尝试使用 css 动画来动画化从一个类到另一个类的变化。基本思想是在用户单击按钮时为从一个边缘滑动到另一个边缘的 slider 设置动画。 到目前为止我的代码。 https://jsfiddle
我目前面临使用前后伪元素淡入导航项的问题。 当我悬停导航项时,它必须将其背景颜色从白色更改为蓝色。没什么疯狂的。但它也必须显示两个背景图像,分别通过将::before 伪元素从 0 更改为 1 和::
有没有简单的方法可以在最近的sqlite版本中修改表,使其与预定义的架构匹配? 架构: war_id INTEGER NOT NULL, clanname VARCHAR(64), clanhomep
我该如何将我的搜索结果变成这样的: http://i.stack.imgur.com/NfPGs.png 结果显示特定术语在单元格中的位置。 我目前有这个基本的搜索脚本: $terms =
我正在尝试使用按钮创建输入字段。但我想要的是,当创建输入字段时,我想用相同的按钮隐藏创建的输入字段。我尝试了 slideToggle 函数,但效果不是很好。 $('#addEmail').one('
我想做这样的事情: Reference of image. 我所做的:两个 UIImagesView,一个带有 UIViewContentModeLeft,另一个带有 UIViewContentMod
我在使用应该修复表中列的插入触发器时遇到了问题: id - auto increment int thread_id - int [NULL] 我想要实现的是将 thread_id 设置
我使用 tinter.after() 每 200 毫秒 刷新一次树莓派上模拟时钟的显示。一开始还可以,但逐渐地,每次刷新之间的时间达到大约 2-3 秒。是否有任何解决方案可以将刷新间隔保持在 200m
我有一个按钮,它使用::after 伪来填充背景。目前它从左到右填充,这在宽度从 0 到 100% 时有意义。但是,我希望它翻转它填充的方式。 a.project--link { margin:
我正在尝试添加带有伪元素:after的下划线来注释一些文本。 我的问题是,我想强调下划线。在此示例中,这是短语“实际上确实可以...”和“ ...不起作用”。 .test { margin-top
鉴于此: This is a test It is 有没有我可以应用到 的 CSS?那它会出现在“This is...”之前,并且在 PREVIOUS LINE 之前吗? float:left; d
我正在使用链接左侧的图像。 现在,我使用图像的::before 属性来显示,但它显示在链接的上方。 我需要对齐它。这是一张照片: Link 我使用的代码是: .vocabulary-duration
我有一个页脚有 与 6 body {background:#bbb;} .main-footer a::after { content: " | "; color: white; mar
我有一个父元素和一些子元素,但我不能直接更改它们的 CSS。所以,我试图在父元素的 CSS 中更改我 child 的 CSS。示例: .parent { & .child {
我可以 div:after { content: "hello" } 但我能否为 hello 文本添加标题,以便当我用鼠标悬停它时显示标题? 谢谢 最佳答案 你不需要伪元素: p { ba
CSS 2.1 :after 和 CSS 3 ::after 伪选择器(除了 ::after 旧浏览器不支持)?是否有任何实际理由使用更新的规范? 最佳答案 这是伪类与伪元素的区别。 除了 ::fir
「掏出钥匙开门,然后在黑暗中摸索着墙壁开关的位置,最后将室内的灯点亮。」 这是一个星期之前,我每天晚上下班回家时的固定戏码,也可能是大部分人每天回家时的经历。这种「一对一」的日常琐碎还有许多许
我正在尝试包装 , ,和具有 的元素修复我无法直接编辑的表单上的某些定位。由于某种原因,当我尝试使用以下代码时: $("label").before(""); $("input[type=tex
我是一名优秀的程序员,十分优秀!