Build a JavaScript-based mobile cms--Build blog (iii.). Refactoring

Source: Internet
Author: User

At present, some basic functional design of Qi CMS is nearing the end, we need to do a simple refactoring after completing the first two parts of the blog. In order to extract the content of the blog to obtain the logic, so after some effort, finally have a little results.

Ink Qi cms Refactoring

The result we want is that we can initialize and render directly, that is, the following result:

Initialize:function () {        this.getblog ();    },    render:function (response) {        var = {about            : Aboutcms,            aboutcompany:urlconfig["Aboutcompany"        };        Response.push (about);        this. $el. HTML (mustache.to_html (blogpoststemplate, Response));    }

is to simplify the logic, to extract the view-independent parts, and the final result is to put in the initialization, obviously we need arender, just temporarily put ininitializeIt should be enough. Here's the final result:

Initialize:function () {        var params= ' #content ';        var about = {            about:aboutcms,            aboutcompany:configure["Aboutcompany"]        };        var blogview = new Renderblog (params, '/1.json ', blogpoststemplate);        Blogview.renderblog (about);    }

We only need to pass in the ID, URL, template, we can return the result, and then use the Getblog section to pass in the parameters. Render the results again so that we can extract the same parts from the two different view.

Build function

So, we need to build a function renderblog, just need to pass id,url,template and so on in the can.

var renderblog = function (params, URL, template) {    this.params = params;    This.url = URL;    This.template = template;};

Using JavaScript to inherit the prototype can achieve such a function, although not very skilled, but still reluctantly used up.

RenderBlog.prototype.renderBlog = function (addinfo) {    var template = this.template;    var params = This.params;    var url = this.url;    var collection = new Blogpostmodel;    Collection.initialize (URL);    Collection.fetch ({        success:function (collection, response) {            if (addinfo!== undefined) {                Response.push ( addinfo);            }            RenderBlog.prototype.render (params, template, response);        }    ); RenderBlog.prototype.render = function (params, template, response) {    $ (params). HTML (mustache.to_html (template, Response));};

In general, the function of the original function is extracted, and then call their own methods. So we can proceed to the next step, but there is no clear direction for the moment.

Other

CMS effect: Ink qi cms

QQ Discussion Group: 344271543

project:  https://github.com/gmszone/moqi.mobi

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.