1

我试图在 Meteoric IonPopup 中有一个评级表。我有一个按钮来显示表单:

Template.thing.events({
  'click [data-action="showReview"]': function(event, template) {
    IonPopup.show({
      title: 'Leave a review',
      cssClass : '',
      templateURL: 'reviewPopup.html',
      buttons: [{ 
        text: 'Cancel',
        type: 'button-default',
        onTap: function(e) {
          e.preventDefault();
        }
      }, {
        text: 'OK',
        type: 'button-positive',
        onTap: function(e) {
          return scope.data.response;
        }
      }]
    });
  }
});

理想情况下应该将 reviewPopup.html 放在正文中

reviewPopup.html

<template name="reviewPopup">
    {{#if currentUser}}
        Rating: {{> rating}}
    {{/if}}  
</template>

<template name="rating">
    <div class="rateit"></div>
</template>

但是我似乎无法让 templateURL 选项起作用。两个模板都在同一个目录中。我认为我给它一个文件名并且它只是将该文件的内容插入正文中是否正确?IonPopup.show 的文档说:

templateUrl: '', // String (optional). The URL of an html template to place in the popup   body.
4

2 回答 2

1

TemplateName 中指定的模板只能包含静态 HTML 内容,否则根本不会呈现。我正在使用以下解决方法来动态插入实际内容:

IonPopup.show({
       title: 'notification',
       templateName: 'dummyTemplate',
        buttons: [{
          text: 'Ok',
          type: 'button-positive',
          onTap: function() {
            IonPopup.close();
            }
        }]
});

//Insert the actual template in the popup:
Blaze.render(Template.actualTemplate, $('#popupContent')[0]);

模板:

<template name="dummyTemplate">
<div id="popupContent>
</div>
</template>

<template name="actualTemplate">
Actual content
</template>
于 2015-10-21T13:50:17.210 回答
1

看起来您指的是离子文档 - 流星遵循离子约定,但不是那么紧密,以至于您可以假设实现是相同的。使用流星的最佳方法是研究示例流星应用程序并查看它们的代码

在这种情况下,来自流星回购的相关代码如下所示:

// Figure out if a template or just a html string was passed
var innerTemplate = '';
if (options.templateName) {
  innerTemplate = Template[options.templateName].renderFunction().value;
} else if (options.template) {
  innerTemplate = '<span>' + options.template + '</span>';
}

..所以看起来您想要使用templateName:模板的名称,而不是 ionic 的templateURL. 希望有帮助!!

于 2015-09-30T22:44:58.800 回答