json ID에서 제품 페이지에 세 가지 카테고리 메타 바를 설정해야합니다. 각 제품 페이지는 페이지에서 임의의 수의 제품을 가질 수 있으며 각 제품은 각 카테고리에 대한 값을 가질 수 있습니다.Hierachy의 Json과 Vars 설정
제품 1에 값이있는 경우이를 사용합니다. 그러나 제품 1에 0 ('없음'범주)이 있거나 정의되지 않은 경우 카테고리 값이 발견 될 때까지 다음 제품으로 넘어가야합니다. 또는 도달 할 경우 '없음'으로 설정됩니다. 제품 비교의 끝. JSON
_jsonmeta = [
{ "Product": 1, "c1": 0, "c2": 1111, "c3": undefined },
{ "Product": 2, "c1": 2222, "c2": 2222, "c3": undefined }];
//should set category1=2222, category2 = 1111, category3 = 0 ('None')
는 다음 나는 항목
function compareJson(json) {
$.each(json, function (i, item) {
//update if applicable
category1 = checkForNullOrZero(item.c1, i);
category2 = checkForNullOrZero(item.c2, i);
category3 = checkForNullOrZero(item.c3, i);
});
가 그럼 난 정렬, 필터, 또는 다른 모든에 대해 현재의 값을 비교하는 방법을 필요로하는 인덱스를 전달하여 각 항목을 설정 제품 '카테고리로 분류됩니다. 여기
function checkForNullOrZero(categoryidarg, indexarg) {
if (categoryidarg == null || typeof categoryidarg === 'undefined') {
//ignore it if undefined
console.log('Ignore: ' + categoryidarg);
}
else if (categoryidarg == 0) {
//check the others because this category is 'None'
console.log('Fall through to next: ' + _jsonmeta[indexarg]);
}
else {
//check the hierarchy to see if this Area trumps the others
console.log('Compare: ' + categoryidarg + ' vs ' + _jsonmeta[indexarg]);
}
//need to return category here
}
}
전체 바이올린입니다 :
http://jsfiddle.net/TheFiddler/6mwpff7p/ 당신도 현재 카테고리 또는 (2) 값 (1) 값을 반환해야하는
checkForNullOrZero
함수에서 그런 식으로 작업을 수행하기 위해
위대한 두 번째 방법이 좋습니다. 나는 그걸로 갈거야, 고마워. – User970008