流星:显示与车把客户端嵌套对象

Meteor : display with handlebars client side nested object

本文关键字:客户端 嵌套 对象 显示 流星      更新时间:2023-09-26

>我有来自助手的 JSON:

 {
  "perms": [
     {
         "userId": "rA5s5jSz7q9ZSCcNJ",
         "perms": [
             {
                 "moduleName": "Gallery",
                 "container": {
                     "ImageUpload": {
                         "addImage": false,
                         "modifyImage": false,
                         "removeImage": false
                     },
                     "Article": {
                         "readArticle": false,
                         "createArticle": false,
                         "modifyArticle": false,
                         "removeArticle": false,
                         "archiveArticle": false
                     }
                 }
             }
         ]
     },
     {
         "userId": "RrmynmmngJEMsRRpk",
         "perms": [
             {
                 "moduleName": "Gallery",
                 "container": {
                     "ImageUpload": {
                         "addImage": false,
                         "modifyImage": false,
                         "removeImage": false
                     },
                     "Article": {
                         "readArticle": false,
                         "createArticle": false,
                         "modifyArticle": false,
                         "removeArticle": false,
                         "archiveArticle": false
                     }
                 }
             }
         ]
     }
 ]

我的JS是:

    'userWithRights':function() {
        Meteor.call('genereObjectPermission',function(err, resp){
           Session.set('responseServer', resp);
           });
        responseServer = Session.get('responseServer')
        return _.map(responseServer, function(value, key) { return {key: key, value: value}; })
    },'iterateInValue':function(){
        return _.map(this, function(value, key) { return {key: key, value: value}; })
}

和我的HTML代码(多次试验的结果):

{{#each userWithRights}}
  <p> {{key}} </p>
  {{#each value}}
    <li>{{this.userId}}</li>
    {{#each perms}}
      <li><li>{{moduleName}}</li></li>
      {{#each test58}}
          <li><li><li>{{key}}</li></li></li
      {{/each }}
    {{/each}}
  {{/each}}
{{/each}}

所以,我对车把有点迷茫,当我必须迭代Object { key : value }我很难成功时,但是当我必须在嵌套在其他对象中的对象中迭代时,我不能:

{"container": { "ImageUpload": { "removeImage": false }}}

我尝试得到这样的结果:

  • rA5s5jSz7q9ZSCcNJ
  • 画廊

  • 图片上传

    • 添加图像 : 真
    • 修改图像:假
    • 删除图像:假
    • 阅读文章 : 真
    • 创建文章 : 假
    • 修改文章:假
您希望

使用 #with 帮助程序并使用@key访问密钥:

{{#each userWithRights}}
  <p> {{key}} </p>
  <ul>
  {{#each value}}
    <li>{{this.userId}}</li>
    {{#each perms}}
      <li>{{moduleName}}</li>
      {{#with container}}
        {{#with ImageUpload}}
          <li>{{@key}}</li>
        {{/with}}
        <ul>
        {{#each ImageUpload}}
          <li>{{@key}}: {{this}}</li>
        {{/each}}
        </ul>
        {{#with Article}}
          <li>{{@key}}</li>
        {{/with}}
        <ul>
        {{#each Article}}
          <li>{{@key}}: {{this}}</li>
        {{/each}}
        </ul>
      {{/with}}
    {{/each}}
  {{/each}}
  </ul>
{{/each}}

希望对您有所帮助!