Construct a Javascript-based mobile CMS-generate a blog (3). refactor and use javascriptcms

Source: Internet
Author: User

Construct a Javascript-based mobile CMS-generate a blog (3). refactor and use javascriptcms

At present, the design of some basic functions of moji CMS is coming to an end. After completing the first two parts of the blog, we need to make a simple reconstruction. In order to extract the logic for obtaining Blog content, after some efforts, we finally achieved some small results.

Reconstruction of mojicms

The desired result can be directly initialized and rendered, that is, the following result:

initialize: function(){        this.getBlog();    },    render: function(response){        var about = {            about:aboutCMS,            aboutcompany:urlConfig["aboutcompany"]        };        response.push(about);        this.$el.html(Mustache.to_html(blogPostsTemplate, response));    }

This is to simplify the logic and extract the parts irrelevant to the View. The final result is put in the initialization. Obviously, we needrender.initializeIt should be enough. The following is 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 the id, url, and template in, then we can return the result, and then use the getBlog part to pass in the parameter. Then, we can extract the same part of two different views.

BUILD functions

Therefore, we need to build a function RenderBlog, just upload the id, url, template, and so on.

var RenderBlog = function (params, url, template) {    this.params = params;    this.url = url;    this.template = template;};

Using Javascript prototype inheritance can achieve such a function. Although it is not very skilled, it is barely used.

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));};

It is generally to extract functions from the original function and then call your own method. So we can proceed to the next step, but there is no clear direction for the moment.

Others

CMS effect: moji CMS

QQ group: 344271543

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


C # technical answers on the sidebar have been added.

You can also define controls by yourself on the left, but third-party controls will be more beautiful. For more information, see.

What you are talking about is that we define the form and set it to dock to a main form.
We did this.
Send me a message if you have any questions.

What is the use of examplesjs in Extjs 3?

A prompt is displayed.
Examples.css works better




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.