日期:2014-05-17  浏览次数:20459 次

MVC的主从表编辑
刚学mvc没几天,想在mvc中搞个webform中gridView的效果
脚本:

(function ($) {

$.fn.nGridView = function () {
var m_Ndatas = new NDatas();
var r = new NRow();
var isInsert = true;
var strHtml = "";

this.addData = function (inputName, displayName) {
m_Ndatas.add(new NData(inputName, displayName));
return this;
};

this.addCell = function () {
var cell = new NCell();
r.Cells.push(cell);
return cell;
};

function NDatas() {
this.datas = new Array();
this.add = function (data) {
this.datas.push(data);
};
this.getI = function (dispalyName) {
var result = "";
$.each(this.datas, function (i, n) {
if (n.displayName.toLowerCase() == dispalyName.toLowerCase()) {
result = n.inputName;
return;
}
});
return result;
};
this.getD = function (inputName) {
var result = "";
$.each(this.datas, function (i, n) {
if (n.inputName.toLowerCase() == inputName.toLowerCase()) {
result = n.displayName;
return;
}
});
return result;
};
this.getIValue = function (tr, dispalyName) {
var result = "";
$.each(this.datas, function (i, n) {
if (n.displayName.toLowerCase() == dispalyName.toLowerCase()) {
result = tr.find("[name='" + n.inputName + "']").val();
return;
}
});
return result;
};
this.setIValue = function (tradd, tr) {
$.each(this.datas, function (i, n) {
tradd.find("[name='" + n.inputName + "']").val(tr.find("[name='" + n.displayName + "']").val());
});
};
this.init = function (paramTr) {
$.each(this.datas, function (i, n) {
paramTr.find("[name='" + n.inputName + "']").val("");
});
};
}
function NData(inputName, displayName) {
this.inputName = inputName;
this.displayName = displayName;
}
function NControl(dataName, normalHtml) {
this.Name = dataName;
this.Html = "<input type=\"hidden\" name=\"[name]\" value=\"[data]\" />[data]";
if (normalHtml) {
this.Html = normalHtml;
}
this.toString = function (paramTr) {
return this.Html.replace(/\[data\]/g, m_Ndatas.getIValue(paramTr, this.Name)).replace(/\[name\]/g, this.Name);
};
}
function NCell(control) {
this.Controls = new Array();
this.toString = function (paramTr) {
var strResult = "<td>";
$.each(this.Controls, function (i, n) {
strResult += n.toString(paramTr);
});
return strResult + "</td>";
};
this.add = function (