简体   繁体   English

手风琴中的刷新按钮

[英]Refresh Button in Accordion

I would like to update the accordion header FormationName information directly from UI when user clicks on refresh button. 当用户单击刷新按钮时,我想直接从UI更新手风琴标题的FormingName信息。

However, in the current design accordion header is updated by hard coded string ("party") just for testing purpose. 但是,在当前设计中,手风琴标头是通过硬编码字符串(“ party”)更新的,仅用于测试目的。 When user clicks on refresh button first accordion header FormationName is updated. 当用户单击“刷新”按钮时,第一个手风琴标题FormationName被更新。

$("#refresh").click(function () {
    myData.offsetFormations[0]["FormationName"] = "party";
    $('#accordion').accordion('destroy');
    build();
});

http://jsfiddle.net/xg7cr0g4/85/ http://jsfiddle.net/xg7cr0g4/85/

Ok, here's what I came up with. 好的,这就是我的想法。 First, add all elements with the class .formationName into an array. 首先,将所有具有.formationName类的元素添加到数组中。 It should have the same length as your myData.offsetFormations : 它的长度应与myData.offsetFormations相同:

var names = [];
var counter = 0;
$(".formationName").each(function(){
   names[counter] = $(this).text();
   counter++;
});

Logging this element will result in an array of 8 names, which have the values of the headers (adjusted or otherwise.) 记录此元素将导致包含8个名称的数组,这些名称具有标头的值(已调整或其他方式)。

Next, loop over your myData.offsetFormations and set the value of [i]["FormationName"] to that of the name array: 接下来,遍历myData.offsetFormations并将[i]["FormationName"]的值设置为名称数组的值:

for(var i = 0; i < myData.offsetFormations.length; i++){
  myData.offsetFormations[i]["FormationName"] = names[i];
} 

Your whole function should look like this: 您的整个功能应如下所示:

$("#refresh").click(function () {
    var names = [];
    var counter = 0;
    $(".formationName").each(function(){
       names[counter] = $(this).text();
        counter++;
    }); 
    for(var i = 0; i < myData.offsetFormations.length; i++){
         myData.offsetFormations[i]["FormationName"] = names[i];
    }

    $('#accordion').accordion('destroy');
    build();
});

And here's the updated fiddle showing the function in action: 这是更新的小提琴,显示了正在起作用的功能:

JSFiddle 的jsfiddle

Hope that helps! 希望有帮助!

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

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