resourceContentManage.js
1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
var $ = require('jquery'),
common = require('../common/common');
var Button=require('./partials/Button1');
/*获取数据*/
var ViewModel={};
var param = location.href.substring(location.href.lastIndexOf("/") + 1);
common.util.__ajax({
url: "/resource/content/resContentIndex",
data: {id: param},
async:false
},function(res) {
ViewModel = res.data;
},true);
var Bll={
__render:function(selecter,templater,data){
$(selecter).html(common.util.__template2($("#"+templater).html(),data) );
}
}
/*第一步,基础模板*/
Bll.__render("#content-list","content-template",ViewModel);
Bll.__render(".contents","template_content_btns",{btns:Button});
/*第二部,把楼层数据转化成数组*/
ViewModel.contentData=ViewModel.contentData;
var obj2Arr = function(obj) {
for(var i in obj) {
if(!isNaN(i)) {
var arr = [];
for(var j in obj) {
arr[parseInt(j)] = obj[j];
}
obj = arr;
break;
} else if (typeof obj[i] == "object"){
obj[i] = obj2Arr(obj[i]);
}
}
return obj;
}
for(var i = 0; i < ViewModel.contentData.length; i++) {
ViewModel.contentData[i].contentData = JSON.stringify(obj2Arr(JSON.parse(ViewModel.contentData[i].contentData)));
}
console.log(ViewModel);