【问题标题】:Meteor , using jquery sortable causes template to be unboundMeteor,使用 jquery sortable 导致模板未绑定
【发布时间】:2012-10-19 07:31:41
【问题描述】:

我有一个具体的问题。我已经使用流星构建了一个应用程序,它基本上在主屏幕中显示了一些实体,这些实体由 Jquery 可排序处理。插入。没什么特别的。

我的行为如下。我有一些事件通过模板机制绑定到每个实体,所以我有 mouseenter,mouse over。

在 jquery 插件中定义了一个占位符。

每当我开始拖放任何实体,并且占位符从其原始位置移动并且从 jquery 触发 onChange 事件时,该实体就会不受流星事件的约束。

但是,如果我通过 jquery 绑定它,它就不会发生。有谁知道会发生什么?

这个问题可以很简单地复制。使用 jQuery 中的可排序示例,提取模板中的 ul create 部分。

<head>
    <title>auth</title>
</head>

<body>
    {{> hello}}
</body>

<template name="hello">
     <ul id="sortable">
{{>items}}
</ul>
</template>
<template name="item">
     {{#if clipped}}
     {{else}}
     {{/if}}    
 <div class="india">
      <li>Item {{this.id}}</li>
 </div>

 </template>

 <template name="items">
       {{#each items}}
            {{>item}}
       {{/each}}

      <div class="empty"/>
      <div class="empty"/>
      <div class="empty"/>
      <div class="empty"/>
      <div class="empty"/>
      <div class="empty"/>        
  </template>

js文件有

Template.hello.rendered = function () {
    $("#sortable").sortable({
    placeholder:"place"
    });
};


Template.items.items = function () {
    var gigi = [];
    for (i=0;i<5;i++){
         gigi[i]={id:i};
    }
    return gigi;
}

Template.item.clipped=function(){
    return true;
};

Template.item.events({
    'mouseenter .india' : function () {
          console.log(this.id);
     }
});

和css文件:

.india{
    height:80px;
    width:80px;
    background-color: red;
    margin:5px;
    float:right;
}
.place{
    height:80px;
    width:80px;
    background-color: blue;
    margin:5px;
    float:right;
 }
 .empty{
    height:80px;
    width:80px;
    background-color: yellow;
    margin:5px;
    float:right;
 }

我在项目模板中包含了帮助程序 Template.item.clipped 的事实导致移动后的项目通过模板 Template.item.events 机制释放绑定到它的所有事件。

【问题讨论】:

  • 你可能想要包含一些代码:)
  • 我无法使用添加了meteor add jquery 的当前 jquery 包和来自 jquery ui 的最新排序来重现此问题。一切都按预期工作,包括拖动。你能指定你使用的jquery、jquery ui和meteor的版本吗?
  • 这仍然是个问题吗?我也无法复制。
  • 也无法重现..
  • 有点离题,但我已经开始将任何旧的未回答的流星问题标记为过于宽泛。 “过于本地化”的关闭原因已经消失。

标签: jquery events map jquery-ui-sortable meteor


【解决方案1】:

Meteor 0.8.0 有一个完全重写的模板引擎。名为烈焰。它应该可以解决人们可能遇到的任何 jQuery 问题。

查看文档http://docs.meteor.com,特别是有关使用 blaze 的 wiki 页面。 https://github.com/meteor/meteor/wiki/Using-Blaze

【讨论】:

    猜你喜欢
    • 2012-05-13
    • 1970-01-01
    • 1970-01-01
    • 2013-06-22
    • 2018-08-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-19
    相关资源
    最近更新 更多