首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将两个Javascripts组合在一起

问将两个Javascripts组合在一起
EN

Stack Overflow用户
提问于 2017-01-29 15:57:49
回答 1查看 72关注 0票数 1

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

代码语言:javascript
复制
{(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";

             }

        }

    });
})();
}
EN

回答 1

Stack Overflow用户

发布于 2017-01-29 16:17:11

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

代码语言:javascript
复制
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';          }

    }

});

仅在函数解密和此行var elStatus = kintone.app.getFieldElements(elStatuss);中进行了更改

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41918791

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档