类似Twitter的微博与Dojo&persever
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了类似Twitter的微博与Dojo&persever相关的知识,希望对你有一定的参考价值。
This source code based on the "friend" example given with Persevere. It is a simple Twitter-like microblogging program. Note that you need to create a class definition file in "WEB-INFjslib weet.js" for it to work.
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <!-- Following Tweet class definition must exist in WEB-INFjslib weet.js: Class( { "id":"Tweet", "name":"Tweet", "schema":{ "extends":{"$ref":"../Class/Object"}, "prototype":{}, "properties":{ "name": { optional:true }, "content": { optional:true } } } }); --> <script type="text/javascript"> onload = function() { // load all the classes from Persevere displayTweets = function() { pjs.load("/Tweet/", function(tweets) { var tableHTML = ""; for(var i = tweets.length -1 ; i >= 0; i--) { var tweet = tweets[i]; var escapedName = tweet.name.replace(/</,''); var escapedContent = tweet.content.replace(/</,''); var age = ((new Date().getTime() - tweet.timestamp) / 1000) + " seconds ago"; tableHTML += "<p>" + escapedName + " : " + escapedContent + " (" + age + ")</p>"; } document.getElementById("list").innerHTML = tableHTML; }); } pjs.loadClasses(/*path*/ null, displayTweets); addTweet_onclic = /*document.getElementById("addTweet").onclick =*/ function() { var name = document.getElementById("sender").value; var message = document.getElementById("message").value; if(typeof Tweet == 'undefined'){ return alert('A "Tweet" class must be created in order for this demo to work'); } if(name && message){ new Tweet({"name":name,"content":message,"timestamp":new Date().getTime()}); // WHY? "message" field (instead of "content") does not work pjs.commit(displayTweets); } }; } </script> </head> <body> <table border='0' margin='5px'> </table> <div id="list" border="1"> </div> </body> </html>
以上是关于类似Twitter的微博与Dojo&persever的主要内容,如果未能解决你的问题,请参考以下文章