2015-04-06 60 views
0

我正试图获得一个简单的MultiSelect工作流星。检查出20个不同的UI库后,我决定Kendo UI看起来最好。Kendo UI不使用流星?

我环顾四周,发现他们已经设置了流星包(据说)很容易在流星中使用Kendo UI。这是我做了尝试和流星使用剑道UI得到一种的Hello World与多选的步骤:

meteor create FindMeFood 
meteor add telerik:kendo-ui-core-fiori-theme 

然后我修改FindMeFood.html

<head> 
    <title>FindMeFood</title> 
</head> 

<body> 
    <label for="where">Where</label> 
    <select id="where" multiple="multiple" data-placeholder="Select where..."> 
     <option>McDonalds</option> 
     <option>Burger King</option> 
     <option>Wendy's</option> 
     <option>Five Guys</option> 
     <option>KFC</option> 
     <option>Taco Bell</option> 
     <option>Pizza Hut</option> 
     <option>Papa Johns</option> 
    </select> 
</body> 

最后修改FindMeFood.js

if (Meteor.isClient) { 
    $("#where").kendoMultiSelect().data("kendoMultiSelect"); 
} 

而且什么也没发生。当我启动Meteor并访问该页面时,我结束了一个标准的多选框。

回答

2

如果你不想惹在这一点上,只需使用一个

meteor version 1.0.4 or >

if(Meteor.isClient){ 
    Template.body.onRendered(function(){ 
     $("#where").kendoMultiSelect().data("kendoMultiSelect"); 
    }) 
    } 

流星1.0.4 or less

if(Meteor.isClient){ 
    Template.body.rendered = function(){ 
    $("#where").kendoMultiSelect().data("kendoMultiSelect"); 
    } 
    } 

为什么rendered function()?与呈现功能,可以确保当DOM准备好,在这种情况下,#where select

+0

@ArtOfWarfare您是否找到解决方法? – Ethaan 2015-04-10 00:23:26

+0

对不起,我正忙着跟我dayjob所有的这一周,也没有机会再回到这个辅助项目直到刚才(耶周末)。不管怎么说,你的解决方案似乎是两个比较简单的,不需要我创造,我会永远只能使用一次模板。所以我将其标记接受。 – ArtOfWarfare 2015-04-11 15:29:31

1

流星是客户端方法可能运行之前,您的HTML呈现在客户端。

尝试这样做,它的工作只是罚款:

  1. 介绍命名模板在.html文件:

    <head> 
        <title>FindMeFood</title> 
    </head> 
    
    <body> 
        {{> kendo}} 
    </body> 
    
    <template name="kendo"> 
        <label for="where">Where</label> 
        <select id="where" multiple="multiple" data-placeholder="Select where..."> 
         <option>McDonalds</option> 
         <option>Burger King</option> 
         <option>Wendy's</option> 
         <option>Five Guys</option> 
         <option>KFC</option> 
         <option>Taco Bell</option> 
         <option>Pizza Hut</option> 
         <option>Papa Johns</option> 
        </select> 
    </template> 
    
  2. 添加onRendered功能,该模板(在你的JS代码) :

    if (Meteor.isClient) { 
        Template.kendo.onRendered(function() { 
        $("#where").kendoMultiSelect().data("kendoMultiSelect"); 
        }); 
    } 
    
  3. H有趣的选择多个位置。

+1

这似乎是一个有效的解决方案,但参与制作,我永远只能使用一个时间模板的代码运行,让我去与另一个提议的解决方案。尽管如此,你的努力+1。谢谢! – ArtOfWarfare 2015-04-11 15:30:26

+0

我同意其他解决方案更一般。 – waeltken 2015-07-06 10:00:08