jqGrid에서 사용자 정의 포맷터 함수를 사용하여 링크 된 다운로드 아이콘이있는 "다운로드"셀을 채 웁니다. 모든 코드를 인라인으로 처리했지만 모든 JS 코드를 사용자 지정 개체로 이동하여 패키지로 만들고 네임 스페이스를 지정했습니다. 자, 사용자 정의 포매터 함수가 호출되면 "this"참조가 jqgrid 테이블로 변경되고 그리드 생성 이전에 생성 된 아이콘 객체를 찾을 수 없습니다.외부 데이터를 사용자 정의 jqGrid 포맷터 함수로 가져 오기
이 모든 것이 의미가 있습니다. 래핑 사용자 지정 개체의 일부인 아이콘 개체를 어떻게 참조 할 수 있는지 궁금합니다. ,
이//loop over the json and build the colmodel, call custom formatter
jQuery.each(jsonObj, function() {
var sdFields = this.supplementalData.fields.field;
len = sdFields.length;
for(var i=0; i<len; i++) {
if(sdFields[i].display) {
var currOption = {};
currOption.name = sdFields[i].id;
currOption.index = sdFields[i].id;
if(sdFields[i].displayType == 'icon') {
currOption.formatter = this.resultsGridFormatter;
} else if(sdFields[i].dataType == 'date') {
//currOption.datefmt = 'mm/dd/YYYY';
currOption.formatter = 'date';
currOption.formatoptions = {
srcformat: 'Y-m-d',
newformat: 'm/d/Y'
};
}
currOption.jsonmap = sdFields[i].id;
currOption.width = sdFields[i].width;
currOption.align = sdFields[i].align;
currOption.sorttype = sdFields[i].dataType;
currOption.sortable = sdFields[i].sortable;
currOption.resizable = sdFields[i].resizeable;
colModel[i] = currOption;
}
}
});
//loop over jsonObj and build the icons object (assoc. array)
this.setIcons = function(jsonObj) {
var iconsObj = {};
jQuery.each(jsonObj, function() {
var sdIcons = this.supplementalData.icons.icon;
var len = sdIcons.length;
for(var i=0; i<len; i++) {
iconsObj[sdIcons[i].id] = sdIcons[i].file;
}
});
this.icons = iconsObj;
};
//custom formatter that formats icon cells by referencing the icons created above
this.resultsGridFormatter = function(cellvalue, options, rowObject) {
console.log(this);
var icons = this.getIcons();
var cellVal = "";
var cssclass = "icon_"+options.colModel.name;
if(cellvalue != null) {
if(cellvalue.indexOf("://") != -1) {
//it is a URL, so link create the icon and link it
cellVal += "<a href='"+cellvalue+"' target='_blank'><img src='"+icons[options.colModel.name]+"' class='"+cssclass+"' /></a>";
}else{
//it is an id, so link to the details modal
cellVal += "<img src='"+icons[options.colModel.name]+"' id='"+cellvalue+"' class='"+cssclass+"' />";
}
} else {
cellVal += " ";
}
//console.log(cellvalue);
//console.log(options);
//console.log(rowObject);
return cellVal;
};
사용자 정의 포맷터에서 내 CONSOLE.LOG 문이있는 jqGrid 테이블을 출력하는 그런 방법이 없기 때문에 따라서 "this.getIcons()"호출이 실패 다음은 관련 코드입니다.
어쨌든 사용자 정의 포매터 내의 아이콘을 참조 할 수 있습니까? 어떻게 든 함수를 포함 시키거나 다른 접근법을 취해야합니까? 첫번째 파라미터 (새 this
값) 그리드 (source code 참조)이다
코드 조각을 게시하고 사용 된 컨텍스트가 아닙니다. 컨텍스트는 'this.resultsGridFormatter = function (...')과 같은 정의에서'this '가 무엇인지 정의합니다. 문제가 발생했습니다. 게시 된 코드에서 이해할 수 없습니다. ** 왜이 코드를 사용합니까? 코드에 접두사를 붙이면됩니다. 따라서 질문에 정보를 추가해야합니다. 가장 좋은 것은 문제를 재현하는 데 사용할 수있는 작은 테스트 코드입니다. – Oleg
전체적으로 http://pastebin.com/DkLe4KQW를 확인하십시오. 사용자 정의 JS 개체입니다 .HTML에서 이렇게 호출됩니다. var ov = new ObjectViewer (uid, path, rurl); ov.buildSearchResults(); – Zendog74