【发布时间】:2010-03-16 17:24:00
【问题描述】:
我有一个新闻提要,其中提要中的项目是根据从服务器返回的 JSON 创建的。当用户对某个项目执行操作时,我想通过 javascript 将其从对象中删除。
Feed 如下所示:
{"newsFeed":[{"feedId":"1",
"title":"item1 title",
"desc":"description of the item"},
{"feedId":"2",
"title":"item2 title",
"desc":"description of the item"}]}
我正在尝试删除一个 JSON 属性或条目,其中 feedId 是通过使用 jQuery 的变量传入的。我不确定我到底哪里出了问题,但是当我在删除对象之前和之后提醒提要时,我得到了相同的响应:
function removeFromFeed(feedId){
var newsFeed=jQuery('div#newsFeed').data('newsFeed');
alert(newsFeed.toSource());
delete newsFeed.feedId[feedId]
jQuery('div#newsFeed').data('newsFeed',newsFeed);
alert(newsFeed.toSource());
}
【问题讨论】:
标签: javascript jquery json object