/**
* @ description Model MVC中M 数据模型
* @ Object
* @ public
* @ create method IE不支持
*/ if(typeof Object.create !== 'function'){
Object.create = function(o){
function F(){}
F.prototype = o;
return new F()
}
} Math.guid = function(){
return 'xxxxxxxx-xxxx-4yxx-xxxxxxxxxxxx'.replace(/[xy]/g,function(c){
var v = Math.random()*16|0,
c = c == 'x' ? v : (v & 0x8),
c = c.toString(16);
return c.toUpperCase()
})
} var Model = {
created : function(){ }, prototype : {
init: function(){
console.log('prototype.init')
}
}, extend : function(o){
for(var i in o){
this[i] = o[i]
}
}, include : function(o){
for(var i in o){
this.prototype[i] = o[i]
}
}, create : function(){
var object = Object.create(this);//object 继承 Model
object.parent = this;
object.prototype = object.fn = Object.create(this.prototype) // object.prototype 继承 Model.prototype
object.created();
return object
}, init : function(){
var instance = Object.create(this.prototype);
instance.parent = this;
instance.init.apply(instance,arguments);
return instance;
}
} /*
*Object 存储实例对象
*/ Model.records = {}; var Asset = Model.create(); Model.include({
init : function(attr){
if(attr){
this.load(attr)
}
},
load : function(attr){
for(var i in attr){
this[i] = attr[i]
}
}
}) Model.include({
newRecords : true, create : function(){
this.newRecords = false;
this.id = this.id || Math.guid();
this.parent.records[this.id] = this.dup();
}, destroy : function(){
delete this.parent.records[this.id]
}, updata : function(){
this.parent.records[this.id] = this.dup();
}, save : function(){
this.newRecords ? this.create() : this.updata()
}, dup : function(){
var o = {};
for(var i in this){
o[i] = this[i]
}
return o;
} }) Model.extend({
find : function(id){
var record = this.records[id]
if(!record) throw('no you need object')
return record.dup()
}, created : function(){
this.record = {}
}
}) Model.extend({
populate : function(values){
this.records = {};
for(var i = 0, len = values.length; i < len; i++){
var record = this.init(values[i]);
record.newRecords = false;
record.id = record.id || Math.guid();
this.records[record.id] = record;
}
}
}) var asset = Asset.init({name : 'xiaohui108'})

自己构建MVC中的M的更多相关文章

  1. 《Entity Framework 6 Recipes》中文翻译系列 (20) -----第四章 ASP.NET MVC中使用实体框架之在MVC中构建一个CRUD示例

    翻译的初衷以及为什么选择<Entity Framework 6 Recipes>来学习,请看本系列开篇 第四章  ASP.NET MVC中使用实体框架 ASP.NET是一个免费的Web框架 ...

  2. ASP.NET Core MVC中构建Web API

    在ASP.NET CORE MVC中,Web API是其中一个功能子集,可以直接使用MVC的特性及路由等功能. 在成功构建 ASP.NET CORE MVC项目之后,选中解决方案,先填加一个API的文 ...

  3. 在ASP.NET Core MVC中构建简单 Web Api

    Getting Started 在 ASP.NET Core MVC 框架中,ASP.NET 团队为我们提供了一整套的用于构建一个 Web 中的各种部分所需的套件,那么有些时候我们只需要做一个简单的 ...

  4. ASP.NET Core MVC 中的 [Controller] 和 [NonController]

    前言 我们知道,在 MVC 应用程序中,有一部分约定的内容.其中关于 Controller 的约定是这样的. 每个 Controller 类的名字以 Controller 结尾,并且放置在 Contr ...

  5. MVC中使用Entity Framework 基于方法的查询学习笔记 (一)

    EF中基于方法的查询方式不同于LINQ和以往的ADO.NET,正因为如此,有必要深入学习一下啦.闲话不多说,现在开始一个MVC项目,在项目中临床学习. 创建MVC项目 1.“文件”--“新建项目”-- ...

  6. 如何在 ASP.NET MVC 中集成 AngularJS(2)

    在如何在 ASP.NET MVC 中集成 AngularJS(1)中,我们介绍了 ASP.NET MVC 捆绑和压缩.应用程序版本自动刷新和工程构建等内容. 下面介绍如何在 ASP.NET MVC 中 ...

  7. 在 ASP.NET MVC 中充分利用 WebGrid (microsoft 官方示例)

    在 ASP.NET MVC 中充分利用 WebGrid https://msdn.microsoft.com/zh-cn/magazine/hh288075.aspx Stuart Leeks 下载代 ...

  8. MVC中的数据注解和验证

    数据注解和验证 用户输入验证在客户端浏览器中需要执行验证逻辑. 在客户端也需要执行. 注解是一种通用机制, 可以用来向框架注入元数据, 同时, 框架不只驱动元数据的验证, 还可以在生成显示和编辑模型的 ...

  9. 如何在 ASP.NET MVC 中集成 AngularJS(1)

    介绍 当涉及到计算机软件的开发时,我想运用所有的最新技术.例如,前端使用最新的 JavaScript 技术,服务器端使用最新的基于 REST 的 Web API 服务.另外,还有最新的数据库技术.最新 ...

随机推荐

  1. ZOJ2928 Mathematical contest in modeling(模拟退火)

    连续两天学了一些numerical analysis的方法,昨天是学了一下三分,今天学了一下模拟退火.很早就听说了模拟退火在求费马点上的运用了,只知道一些大概,但是没有深入研究,碰到题目就卡壳了,现在 ...

  2. Javascript 事件冒泡

    <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...

  3. C# 实现抓取网站页面内容

    抓取新浪网的新闻栏目,如图所示: 使用 谷歌浏览器的查看源代码: 通过分析得知,我们所要找的内容在以下两个标签之间: <!-- publish_helper name='要闻-新闻' p_id= ...

  4. SSH 使用JUnit测试

    前提是引入两个包:org.springframework.test-3.1.3.RELEASE和JUnit4. package com.qk.test; import javax.annotation ...

  5. 可任意自定义的 UITableViewCell

    可任意自定义的 UITableViewCell UITableView的强大更多程度上来自于可以任意自定义UITableViewCell单元格.通常,UITableView中的Cell是动态的,在使用 ...

  6. java jms

    这篇博文我们主要介绍J2EE中的一个重要规范JMS,因为这个规范在企业中的应用十分的广泛,也比较重要,我们主要介绍JMS的基本概念和它的模式,消息的消费以及JMS编程步骤. 基本概念 JMS是java ...

  7. 高性能jdbc封装工具 Apache Commons DbUtils 1.6(转载)

    转载自原文地址:http://gao-xianglong.iteye.com/blog/2166444 前言 关于Apache的DbUtils中间件或许了解的人并不多,大部分开发人员在生成环境中更多的 ...

  8. 通用sqlserver分页存储过程

    来自:http://www.cnblogs.com/vagerent/archive/2007/10/17/927825.html 单主键: CREATE PROC P_viewPage    /** ...

  9. C# 字符串计算表达式

     C#  字符串计算表达式 string str="4+4+2.1"; 要的效果: double sum=4+4+2.1: 方案一: 动态计算表达式: 1 public class ...

  10. windows服务删除后,在次安装时无法安装启动。

    当我在windows的cmd下卸载evtsys evtsys -u  再次安装时evtsys.exe -i -h 192.168.32.12 -p 514 提示“指定的服务已标记为删除”,进入服务管理 ...