前端MVC里model是模型,一些通用的方法,应该是model还是controller?
admin 发布于 1476677052

MVC的概念看了一些,感觉理解还是没有很透彻,在实际应用中还是有一些不知道属于model还是controller?MVC里model是模型,如我有一些通用的方法(主要是操作DOM和获取)放在appUtil对象里,应该属于model还是controller?

//方法:主要是获取数据,生成HTML元素,插入页面的方法//下面这个方法集合应该是 放在controller里还是model呢?

var monitorUtil = {
getEventTarget: function(e) {
//event.target(IE)和event.srcElement(其他浏览器)返回事件目标节点
e = e || window.event();
return e.target || e.srcElement;
},
setLocalStorage: function(type) {
//oldHeatSourceData oldHeatStationData oldPipeData oldDeviceData
var oldInnerHtml;
switch(type) {
case "heatSource":
oldInnerHtml = mui('.mui-table-view')[0].innerHTML;
localStorage.setItem("oldHeatSourceData", oldInnerHtml);
break;
case "heatTransfer":

oldInnerHtml = mui('.mui-table-view')[1].innerHTML;
localStorage.setItem("oldHeatStationData", oldInnerHtml);
break;
case "heatSupply":

oldInnerHtml = mui('.mui-table-view')[2].innerHTML;
localStorage.setItem("oldPipeData", oldInnerHtml);
break;
case "encironmental":
oldInnerHtml = mui('.mui-table-view')[3].innerHTML;
localStorage.setItem("oldDeviceData", oldInnerHtml);
break;
default:

break;
}
},
/*如果本地没有存储响应的数据调用这个方法,获取服务器数据*/
getMonitorData:function(url, targetUl, pageData, whichTab) {
mui.ajax({
async: false, //同步
data: pageData,
type: 'POST',
url: url,
timeout: 3000,
headers: {
Accept: "text/html, application/xhtml+xml, */*" //解决406报错
},
success: function(data) {
console.log(data);
var len = data.length;
targetUl.innerHTML = ""; //刷新前清空原数据
if(data == '' || !data) {
var p = doc.createElement('p');
console.log(p);
console.log(url);
p.className = "no-more-data";
p.innerHTML = "暂无数据";
targetUl.appendChild(p);
} else {
targetUl.appendChild(monitorUtil.createFragment(len, data, whichTab)); //调用函数,插入创建的元素
}
},
error: function(xhr, type, errorThrown) {
mui.toast("连接超时,请检查网络!");
console.log(xhr + '\n' + type + '\n' + errorThrown);
}
});
}
}