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