码迷,mamicode.com
首页 > 其他好文 > 详细

Backbone introduce

时间:2014-08-15 01:15:47      阅读:264      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   http   color   java   os   io   

I had immersed in web developer more than one year. during this past year, I read a lot of books about fond-end.

from css,javascript,jquery and html. especial books about javascript. Yes, Javascript one one lauguange which you perhaps love and hate together.

but anyway, I want to move on about this laungage.

During code with Javascript, I encountered many problem which I never encountered before, this is the reason which I want to try to learn BackBone in detail.

Basic I will try to learn this js framework from www.backbonejs.org only. I will record my practise in this blog step by step.

OK,Let me have a look my first backbone demo. add underscore.js and backbone.js two files in Scripts folder. use Asp.net mvc4 bundle and minifaction framework to bundle those two scripts. one strange thing is that you should first include ‘underscore.js‘ file, current I don‘t know the reason. I will pay attention to this later.

bubuko.com,布布扣

second, refer to this package in _layout.cshtml,

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8" />
        <title>@ViewBag.Title - My ASP.NET MVC Application</title>
        <link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" />
        <meta name="viewport" content="width=device-width" />
        @Scripts.Render("~/bundles/backbone")

 

third, add one action(and its view) under HomeController

//Demo action
public
ActionResult Demo() { return View(); }
//Demo.cshtml
@{ ViewBag.Title = "Demo"; }
<script type="text/javascript" src="~/Scripts/demo.js"></script> <h2>Demo</h2>

last in demo.js file, we use backbone to raise one later event.

(function () {
    var object = {};

    _.extend(object, Backbone.Events);

    object.on("alert", function (msg) {
        alert("Triggered " + msg);
    });

    object.trigger("alert", "an event");
})();

now Demo done, in IE address,input:http://localhost:49983/Home/Demo, you can see its output.

bubuko.com,布布扣

this demo is just showing brief usage of backbone. no detail explanation about it. I will dig into backbone.js to find what is benefit of this js framwork comparing with common js framework. see you.

Backbone introduce,布布扣,bubuko.com

Backbone introduce

标签:des   style   blog   http   color   java   os   io   

原文地址:http://www.cnblogs.com/pureni/p/3905509.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!