是否可以通过ajax(而不是预先)在类似时间线中动态加载内容
我正在使用 javascript 明喻时间线 有一个时间线项目非常大描述字段。我不想让我的初始 json 有效负载数据膨胀,因为只有在以下情况下才需要这些数据: 有人单击时间线项目。
例如,对于这个 JSON 结果:
{
'dateTimeFormat': 'iso8601',
'wikiURL': "http://simile.mit.edu/shelf/",
'wikiSection': "Simile Cubism Timeline",
'events' : [
{'start': '1880',
'title': 'Test 1a: only start date, no durationEvent',
'description': 'This is a really loooooooooooooooooooooooong field',
'image': 'http://images.allposters.com/images/AWI/NR096_b.jpg',
'link': 'http://www.allposters.com/-sp/Barfusserkirche-1924-Posters_i1116895_.htm'
},
我希望从 JSON 中一起删除描述字段(或发送 null),并让它通过另一个 ajax 调用按需加载它。
无论如何,在初始加载期间不发送描述字段,当有人单击时间线项目时,它会通过ajax加载描述,当时
我认为这将是一个常见功能,但我找不到它
i am using the javascript simile timeline have a timeline items with very large description fields. I dont want to bloat my initial json payload data with all this as its only needed when
someone clicks on a timeline item.
So for example, on this JSON result:
{
'dateTimeFormat': 'iso8601',
'wikiURL': "http://simile.mit.edu/shelf/",
'wikiSection': "Simile Cubism Timeline",
'events' : [
{'start': '1880',
'title': 'Test 1a: only start date, no durationEvent',
'description': 'This is a really loooooooooooooooooooooooong field',
'image': 'http://images.allposters.com/images/AWI/NR096_b.jpg',
'link': 'http://www.allposters.com/-sp/Barfusserkirche-1924-Posters_i1116895_.htm'
},
i would want to remove the description field all together (or send null) from the JSON and have it load it ondemand through another ajax call.
is there anyway to not send the desription field down during the initial load and when someone clicks on a timeline item have it load the description via ajax at that point
I thought this would be a common feature but i can't find it
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我认为您需要做的事情类似于 @dacracot 所建议的,但您可以利用时间线文档中描述的一些处理程序,特别是
onClick
处理程序。所以我想象你做的是这样的:至少有一个部分我还没有回答,那就是如何确定哪个事件被点击,但你可能可以从
evt.getID()< /code>
编辑:哦,另一个棘手的部分可能是如何将描述插入到时间线数据中。我只是对时间轴这个东西不够熟悉,不知道它是如何完成的。
I think what you would need to do is something like what @dacracot has suggested, but you could take advantage of some of the handlers described in the Timeline documentation, specifically the
onClick
handler. So what I'm imagining you do is this:There's at least one part I haven't answered, which is how to figure out which event was clicked, but you could probably figure it out from
evt.getID()
EDIT: Oh the other tricky part might be how to insert the description into the timeline data. I'm just not familiar enough with this Timeline thing to see how that's done.
所以我想知道您是否可以放置一个脚本来调用描述。
稍微分解一下...
这是您更新 javascript 中的 insideHTML 的地方:
这是进行 ajax 调用并更新 innerHTML 的 javascript:
最后,这是将正确的描述放入正确位置的 javascript 调用:
我承认我还没有尝试过,但这可能是一个开始。
So I wonder if you could place a script call the description.
Breaking it down a bit...
This is where you would update the innerHTML in you javascript:
This is the javascript which makes the ajax call and updates the innerHTML:
Finally, this is the javascript call to get the right description into the right location:
I admit that I haven't tried this, but it may be a start.
我还必须在 ASP.NET MVC 应用程序中执行类似的操作。
就我而言,我必须在页面加载时执行此操作。您也可以在某些条件\事件下执行此操作。
我所做的是,当我的页面加载时,我向我的部分视图控制器发出了 GET 请求。从那里我返回了一个“PartialViewResult”。然后在 UI 中我将其放置在需要渲染的位置。
请注意,在控制器中,有不同的方法来渲染部分视图。
我没有在控制器中对 UI Html 进行硬编码。这不是一个好的做法。我得到的 UI 渲染方式为:
基本上,您的视图引擎正在渲染 UI Html。 :)
如果您想查看我的实现,请点击链接: http://www .realestatebazaar.com.bd/buy/property/search
希望有帮助。
I also had to do something like that in an asp.net MVC Application.
In my case i had to do it on a page load. You can do it on some conditions\events too.
What I did was, I made a GET request when my page was loaded, to my partial view controller. From there I returned a "PartialViewResult". Then in the UI I placed it where it needed to be rendered.
Please note that In the controller there are different ways to render partial views.
I did not hard code the UI Html in the controller. That wouldn't be a good practice. I got the UI rendered by:
Which is basically your view engine is rendering the UI Html. :)
If you want to have a look at my implementation here is the link: http://www.realestatebazaar.com.bd/buy/property/search
Hope that helps.
这是一个非常酷的解决方案,如果您愿意使用 Jquery,可以使用 AJAX。非常好的结果!
http://tutorialzine.com/2010/01 /高级事件时间线-with-php-css-jquery/
This is a pretty cool solution that --could-- use AJAX if you were so inclined via Jquery. Very nice result!
http://tutorialzine.com/2010/01/advanced-event-timeline-with-php-css-jquery/
我假设您使用的是 PHP,并且在字符串中包含示例 JSON:
显然您只会输出免费的描述,或者唯一的描述;取决于要求。
编辑:修复了代码以正确地说 unset() 而不是 unshift(),印刷错误...
编辑2:MXHR(Multipart XmlHttpRequest)涉及创建所有描述的字符串,并用分隔符分隔。
并请求该长字符串。当它下降时,您可以读取流并通过搜索
||
拆分任何已完成的流。I'm assuming you're using PHP, and have the sample JSON in a String:
Obviously you'd only output the description free, or the only descriptions; depending on what's requested.
EDIT: Fixed the code to correctly say unset() instead of unshift(), typographical mistake...
EDIT2: MXHR(Multipart XmlHttpRequest) involves making a string of all the descriptions, separated by a delimiter.
And make a request for that long string. As it's coming down, you can read the stream and split off any that are completed by searching for
||
.那将是服务器端问题。您无法更改前端的数据以使结果更小,因为您已经有了结果。
使用不同的调用或添加参数。
That would be a server side issue. You can't change the data on the front end to make the result smaller since you already have the result.
Use a different call or add parameters.