如何强制Template.dynamic重新渲染

时间:2015-06-25 13:28:33

标签: javascript meteor

我阅读并尝试了很多解决方案,但我无法强制模板动态再次渲染。

在html>>

import com.atpl.buzzor.application.service.ApplicationServicePortType;
import http.model_application_buzzor_atpl.ApplicationResult;
import http.model_application_buzzor_atpl.Application;
import http.model_application_buzzor_atpl.User;
public class SoapUtils {
    @Inject
    private ApplicationServicePortType applicationService;

    public void invokeWebserviceAndGetResponse(Exchange exchange) {
         java.lang.String response = applicationService.getApplication();
         ..or..
         Application application = new Application(); //or whichever way you generate this.
         User user = new User(); //or which ever way u generate this.
         ApplicationResult result = applicationService.addApplication(application,user);
         ...
    }
}

在Meteor.isClient>>

<body>
    {{> Template.dynamic template=Template}}
</body>

我在Template.body.helpers({ 'Template': function() { return page.template; } }); hashchange上有一个功能,它会更改event的{​​{1}},value工作正常,每次都会更改值,但是我无法强制page.template再次渲染。

event是字符串

我有一个函数Template.dynamic只是为了尝试所有选项

我正在使用最新版本的Meteor page.template

2 个答案:

答案 0 :(得分:3)

我不确定您的应用是如何组织的,但这应该是一件容易的事。只需使用ReactiveVar即可保存您希望选择的活动模板名称。

我为你制作了一个简单的MeteorPad。希望这就是你要找的东西。

http://meteorpad.com/pad/oPhK4KqjiSztRSa9K/SimpleDynamicTemplateSwitch

干杯 汤姆

答案 1 :(得分:2)

在开始之前,我更改了一些对象,page.template现在是对象,page.template.get()将返回字符串,但我不使用它,我在template name中传递Sessions },这是我的page.template.set()

page.template.set = function(name) {
    Session.set('template', name);
  };

我找到了答案,你需要设置一个依赖于Sessions,到目前为止我已经完成了这个

Template.body.helpers({
    'Template': function() {
      return Session.get('template');
    }
  });
  

编辑   由于客户端黑客,我决定改变一些东西(你可以在控制台中更改会话,我希望我的路由器决定应该显示哪个模板)

page.template.set = function(name) {
  page.template.name = name;
  Session.set('template', name);
};
page.template.get = function() {
  return page.template.name;
};

Template.body.helpers({
  'Template': function() {
     return Session.get('template') ? page.template.get() : page.template.get();
  }
});
相关问题