2012-09-04 3 views
1

couchdb에서 첨부 파일 이름을 렌더링하십시오. 변환없이 핸들 막대 또는 콧수염 템플리트를 사용하십시오.변환하지 않고 couchdb에서 첨부 파일 이름을 렌더링하십시오.

{ 
    "_id":"123", 
    "_attachments":{ 
     "evil.jpg":{ 
     "content_type":"image/jpeg", 
     "revpos":32, 
     "digest":"md5-CKtT5WWRLkmGDD3/DhK6FQ==", 
     "length":41915, 
     "stub":true 
     } 
    } 
} 

나는 이것이 Getting key's in handlebar과 중복 된 것으로 생각합니다. 핸들의

// based on the `#each` helper, requires jQuery (for jQuery.extend) 
Handlebars.registerHelper('each_hash', function(context, options) { 
    var fn = options.fn, inverse = options.inverse; 
    var ret = ""; 

    if(typeof context === "object") { 
     for(var key in context) { 
      if(context.hasOwnProperty(key)) { 
       // clone the context so it's not 
       // modified by the template-engine when 
       // setting "_key" 
       var ctx = jQuery.extend(
        {"_key":key}, 
        context[key]); 

       ret = ret + fn(ctx); 
      } 
     } 
    } else { 
     ret = inverse(this); 
    } 
    return ret; 
}); 

답변

1

개발자는 단지를 추가하려는 경우 도우미 어쨌든 일을해야

putting this in을 논의하고있다. 귀하의 템플릿은 이와 같을 것입니다.

{{#each_hash _attachments}} 
    {{_key}} - {{content_type}} 
{{else}} 
    You didn't pass in an object! 
{{/each_hash}} 

도우미는 본질적으로 개체를 반복하고 즉시 변환을 수행합니다. 객체를 반복하고 키를 _key 변수로 추가합니다. else 문을 포함 할 필요가 없으며 기본적으로 아무 것도 반환하지 않습니다.

관련 문제