resourceContentManage.js 1.31 KB
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);