简体   繁体   English

Seaside & jQuery UI:可排序列表不起作用?

[英]Seaside & jQuery UI: Sortable list not working?

Beginner here.初学者在这里。 I'm currently trying to learn Seaside, and how to integrate jQuery with it.我目前正在尝试学习 Seaside,以及如何将 jQuery 与其集成。 I've been trying to implement some of the examples provided in the Seaside jQuery UI Functional Test Suite in my own image.我一直在尝试在我自己的图像中实现 Seaside jQuery UI 功能测试套件中提供的一些示例。

For some reason, I can't get a sortable list to work.出于某种原因,我无法让可排序的列表起作用。 I copy & pasted the code from the example but it doesn't work.我复制并粘贴了示例中的代码,但它不起作用。 I have made sure to add the jQuery library, and have tested that it works with a clickable animated heading.我确保添加了 jQuery 库,并测试了它是否适用于可点击的动画标题。 But my sortable list just gets rendered with no interaction.但是我的可排序列表只是在没有交互的情况下呈现。

Inspecting the page source does reveal an error message: "TypeError: undefined is not a function(...)", but I don't understand what this means?检查页面源确实会显示一条错误消息:“TypeError:undefined is not a function(...)”,但我不明白这是什么意思?

Any help would be greatly appreciated.任何帮助将不胜感激。 I want to get the hang of this and need to understand why it's not working.我想掌握这一点,并且需要了解它为什么不起作用。 See my code below, as copied exactly from their example, with the exception of assigning a list to the items variable:请参阅下面的代码,完全从他们的示例中复制,除了将列表分配给 items 变量:

| items |
    items := OrderedCollection newFrom: {'peas' . 'carrots' . 'beetroot'}.
   html unorderedList
      script: (html jQuery new sortable
         onStop: (html jQuery ajax
            callback: [ :values | items := values ]
            passengers: (html jQuery this find: 'li')));
      with: [
         items do: [ :each |
            html listItem
               class: 'ui-corner-all';
               passenger: each;
               with: each ] ]

And including the jQuery code as rendered in the browser:并包括在浏览器中呈现的 jQuery 代码:

function onLoad() {
        $("#id3").sortable({              <-- TypeError occurs here
            "stop": function() {
                $.ajax({
                    "url": "/jquery",
                    "data": ["_s=To5SuUU8YuW_HSjD", "_k=MpvlOw_BWjmgF9Uy", "1", "2=" + encodeURIComponent($.map($(this).find("li").get(), function(each) {
                        return each.id
                    }).join(","))].join("&")

Did you also add the jQueryUI library?您是否还添加了 jQueryUI 库? I would think the 'sortable' is not found on a jQuery... so it probably is not loaded.我认为在 jQuery 上找不到“可排序”...所以它可能没有加载。

There are a few things to remark.有几点需要说明。

  1. sortable ( JQSortable class) comes with jQuery UI, so first be sure to include the jQuery UI library in your Seaside application (eg JQUiDevelopmentLibrary ). sortableJQSortable类)带有 jQuery UI,所以首先确保在你的 Seaside 应用程序中包含 jQuery UI 库(例如JQUiDevelopmentLibrary )。

  2. The items variable is a method temporary variable, so it will always have new items in that order. items变量是一个方法临时变量,因此它将始终按该顺序包含新项目。 It should be an instance variable (but I guess you did it so for the purpose of this Stack Overflow example).它应该是一个实例变量(但我猜你这样做是为了这个 Stack Overflow 示例的目的)。

  3. The this object in the ajax function doesn't refer to the list element anymore. ajax function 中的this object 不再引用列表元素。 I added an id to the <ul> tag ( id: 'list' ) and I'm referencing such jQuery object from within the JS object passed to the onStop: handler.我在<ul>标签 ( id: 'list' ) 中添加了一个 id,并且我从传递给onStop:处理程序的 JS object 中引用了这样的 jQuery object。

With these changes I could make it work.通过这些更改,我可以使它工作。


renderContentOn: html
    items := items
        ifNil: [ OrderedCollection newFrom: {'peas' . 'carrots' . 'beetroot'} ].
    html unorderedList
        id: 'list';
        script:
            (html jQuery new sortable
                onStop:
                    (html jQuery ajax
                        callback: [ :values | items := values ]
                        passengers: ((html jQuery id: 'list') find: 'li')));
        with: [ items
                do: [ :each | 
                    html listItem
                        class: 'ui-corner-all';
                        passenger: each;
                        with: each ] ]   

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM