I'm trying to get on with Script# library and find it challenging to get some jQuery ba开发者_开发问答sed Ajax code written. Is there any beginner's tutorial or important API documentation that can get me started real quick?
Since you mentioned you're new to jQuery I would at least start with the jQuery documentation and get comfortable with the basics (see jQuery Documentation).
Once you are comfortable with jQuery, using it in Script# is fairly straight-forward because Script# already includes bindings for jQuery. To get started:
- Make sure you're including jQuery in your HTML page or templates, as you would normally for jQuery (e.g.
<script src="[jQuery]"></script>
). - Verify your Script# project has a reference to
Script.jQuery(.dll)
. - Within your
.cs
source file(s) addusing jQueryApi;
(for convenience). This is the namespace containing Script#'s jQuery bindings.
Now you can utilize jQuery in your Script# code, in a fashion that maps fairly 1:1 to if you were using jQuery within JavaScript. The biggest difference though is in how you first create a jQuery object.
In JavaScript:
// selector
var paragraphs = $("p");
// ad-hoc html
var someHtml = $("<strong>hello</strong>");
// existing DOM element
var elementFromDom = $(document.getElementById("myDiv"));
// ready callback
$(function() { doSomething(); });
In Script#/C#:
// selector
jQueryObject paragraphs = jQuery.Select("p");
// ad-hoc html
jQueryObject someHtml = jQuery.FromHtml("<strong>hello</strong>");
// existing DOM element
jQueryObject elementFromDom = jQuery.FromElement(Document.GetElementById("myDiv"));
// ready callback
jQuery.OnDocumentReady(delegate { DoSomething(); });
Recently at MIX11, Nikhil Kothari, the creator of Script# delivered a very good session on Script# followed by a nice blog post covering how to use Script# with jQuery. This is perfect for the beginners. Below are the links for the video of the session and the followed blog post
video - http://channel9.msdn.com/Events/MIX/MIX11/HTM16
archived blog post - http://web.archive.org/web/20110421060154/http://www.nikhilk.net/ScriptSharp-MIX11.aspx
精彩评论