简体   繁体   English

加载后在Sencha Touch中更新列表项

[英]Update a List Item in Sencha Touch After Loading

I am using using Sencha Touch to make a web-mobile-app. 我正在使用Sencha Touch制作网络移动应用。 I'm not extremely familiar with the way EXTJS works. 我对EXTJS的工作方式不是很熟悉。 I set up my list like this: 我这样设置清单:

sink.Structure = [{
        text: 'Name'
    },
    {
        text: '&nbsp;&nbsp;&nbsp;<?php echo $name; ?>'
    },
    {
        text: 'Friend'
    },
    {
        text: '&nbsp;&nbsp;&nbsp;<?php echo $friend; ?>'
    },
    {
        text: 'Shop'
    },
    {
        text: '&nbsp;&nbsp;&nbsp;<?php echo $shop; ?>'
    }];

            Ext.regModel('Demo', {
            fields: [
                {name: 'text',        type: 'string'},
                {name: 'source',      type: 'string'},
                {name: 'preventHide', type: 'boolean'},
                {name: 'animation'},
                {name: 'card'}
            ]
        });

        sink.StructureStore = new Ext.data.TreeStore({
            model: 'Demo',
            root: {
                items: sink.Structure
            },
            proxy: {
                type: 'ajax',
                reader: {
                    type: 'tree',
                    root: 'items'
                }
            }
        });

So this renders the list perfectly, exactly what I want it to but how do I change the value of the row that echos $name; 这样就完美地呈现了列表,正是我想要的,但是如何更改回显$ name的行的值;

On initial load I have the value in a PHP variable but if the user changes it I want it to change the value of this. 在初始加载时,我在PHP变量中具有该值,但是如果用户对其进行更改,则希望它更改其值。 Do I need to rewrite the whole structure? 我需要重写整个结构吗?

In Jquery I could just give the element an ID an then alter it's .html contents. 在Jquery中,我可以给元素一个ID,然后更改它的.html内容。 But I've noticed that the way this is structured my list item doesn't have any identifying selector which I could use to reference it. 但是我注意到,列表项的结构方式没有任何可用来引用它的识别选择器。 Any advice would help, thank you! 任何建议都会有所帮助,谢谢!

UPDATE: So I made some progress with this, instead of echoing the PHP Variable inside the List Structure, I print a Javascript variable called name which is set initially as the PHP variable. 更新:因此,我在此上取得了一些进展,而不是在列表结构中回显PHP变量,而是打印了一个名为name的Javascript变量,该变量最初设置为PHP变量。 I also, put the sink.Structure setup in a function which takes in the values and then is supposed to reset them, but it doesn't. 我还将sink.Structure设置放入一个函数中,该函数接受值,然后应该将其重置,但事实并非如此。 I've tried making the function include the sink.StructureStore as it seems this is whats rendering the list (maybe? this is a guess) and also just the sink.Structure array list, but nothing seems to affect the list thats already been set, please help! 我试图使函数包括接收器.structureStore,因为似乎这是呈现列表的内容(也许吗?这是一个猜测),也只是接收器。结构数组列表,但似乎没有什么影响已经设置的列表, 请帮忙!

Lists are data bound. 列表是数据绑定的。 Update the data in the underlying data store and any lists which are bound to the data store will automatically update their user interface. 更新基础数据存储中的数据,绑定到该数据存储的任何列表都将自动更新其用户界面。

  1. You have to update your Data.Store with new values. 您必须使用新值更新Data.Store。
  2. YourList.bindStore(YourStore); YourList.bindStore(YourStore);
  3. The second line of code automatically populate the list. 第二行代码自动填充列表。

I have to say I'm disappointed with the way Sencha Touch works in this regard, it appears the list is rendered at first load and cannot be re-rendered because it dynamically creates all the div's with a class of "x-list-item." 我不得不说,我对Sencha Touch的工作方式感到失望,它似乎是在第一次加载时就渲染了列表,因此无法重新渲染,因为它动态创建了所有带有“ x-list-item”类的div。 ”。 I've tried numerous methods to try to get rid of the list and recreate a new one but to no avail. 我尝试了许多方法来摆脱列表并重新创建一个新列表,但无济于事。

The ONLY way I managed to get this to work was by putting in a div tag inside a list element with an id and then using JQuery to select the element and alter it's html. 我设法使它起作用的唯一方法是,将div标签放入具有ID的list元素内,然后使用JQuery选择元素并更改其html。 This is the first app I've made with Sencha Touch and I hope its the last. 这是我使用Sencha Touch开发的第一个应用程序,希望它是最后一个。

The only reason why we went with this is because of its compatibility with Android, but loading the app on the Android Emulator (2.2) none of the page-flick animations worked anyway! 我们这样做的唯一原因是因为它与Android兼容,但是在Android Emulator(2.2)上加载该应用程序后,所有页面翻转动画都无法正常工作! Also, tested on Nexus One, it did load faster but slide transitions were absent. 另外,在Nexus One上进行了测试,它的加载速度更快,但没有幻灯片切换。 Even though there are a few more capabilities of Sencha, JQTouch is certainly my preference when it comes to web-mobile-apps. 尽管Sencha还有更多功能,但对于Web移动应用程序,我当然更喜欢JQTouch。 Sorry just had to get that off my chest :) 对不起,只好把它从我的胸口拿走:)

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

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