【问题标题】:Combine two Javascripts together将两个 Javascript 组合在一起
【发布时间】:2017-01-29 07:57:49
【问题描述】:

*编辑了我的帖子。我需要帮助编辑下面的脚本。此脚本用于对索引视图页面上表格中的元素字段进行颜色格式化。我需要能够对另一个字段值为“Schstatus”的元素字段进行颜色格式化,就像另一个字段的值为“Attendance”一样。我需要添加什么来定义“Schstatus”字段的格式?

{(function() {

    "use strict";
    // Run an event when the record list page is displayed
    kintone.events.on('app.record.index.show', function(event) {

        //Retrieve an array of field elements of the fields with field code of "Attendance"
        var elStatus = kintone.app.getFieldElements('Attendance');

        //Change the properties of the retrieved field elements for each record
        for (var i = 0; i < elStatus.length; i++) 
        {
            var record = event.records[i];
            if (record['Attendance']['value'] === "Call Out") 
            {
                elStatus[i].style.color = 'white';
                elStatus[i].style.backgroundColor = "#e74c3c";

            } 

            else if (record['Attendance']['value'] === "Pending")
             {
                elStatus[i].style.color = 'black';
                elStatus[i].style.backgroundColor = "#ffcc00";
             }

             else if (record['Attendance']['value'] === "Confirmed")
             {
                elStatus[i].style.color = 'white';
                elStatus[i].style.backgroundColor = "#a3b815";

             }

        }

    });
})();
}

【问题讨论】:

  • 另外 - 用this 视频腾出 90 分钟。如果您熟悉其他编程语言,那么它应该会给您在 JS 上的巨大提升

标签: javascript html arrays


【解决方案1】:

将您的 elStatuss 作为函数参数传递。

function your_function_name(elStatuss) {

"use strict";
// Run an event when the record list page is displayed
kintone.events.on('app.record.index.show', function(event) {

    //Retrieve an array of field elements of the fields with field code of one that is given as param.
    var elStatus = kintone.app.getFieldElements(elStatuss);

    //Change the properties of the retrieved field elements for each record
    for (var i = 0; i < elStatus.length; i++) 
    {   var record = event.records[i];
        if (record['Attendance']['value'] === "No-Show") 

    {   elStatus[i].style.color = 'white';
        elStatus[i].style.backgroundColor = 'red';  } 


    else if (record['Attendance']['value'] === "Late")
    {   elStatus[i].style.color = "#a023bc";        }


    else if (record['Attendance']['value'] === "On-Time")
    {   elStatus[i].style.color = 'green';          }

    }

});

仅在函数 decleration 和这一行 var elStatus = kintone.app.getFieldElements(elStatuss); 中进行了更改

然后使用your_function_name('Attendance');your_function_name('Schstatus');

【讨论】:

  • 感谢卡利斯的回复。我刚刚编辑了帖子,听起来不那么困惑..
猜你喜欢
  • 1970-01-01
  • 2013-09-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-07-22
  • 1970-01-01
  • 2023-04-07
  • 1970-01-01
相关资源
最近更新 更多