Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/428.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使剑道网格颜色货币_Javascript_Css_Kendo Ui_Kendo Grid - Fatal编程技术网

Javascript 如何使剑道网格颜色货币

Javascript 如何使剑道网格颜色货币,javascript,css,kendo-ui,kendo-grid,Javascript,Css,Kendo Ui,Kendo Grid,我希望此网格列字段中的所有负值显示为红色,所有正值显示为绿色。此代码用于列对象数组: { field: "Amount", title: "Balance", format: "{0:c}", attributes: { style: "text-align: right;" }, template: "<font class='#if(Amount < 0) {# negative_field #} else {# positive_field #}'></font&g

我希望此网格列字段中的所有负值显示为红色,所有正值显示为绿色。此代码用于列对象数组:

{ field: "Amount", title: "Balance", format: "{0:c}", attributes: { style: "text-align: right;" }, template: "<font class='#if(Amount < 0) {# negative_field #} else {# positive_field #}'></font>" },
你是这样做的:

剑道格网

{ field: "Amount", title: "Balance", attributes: { style: "text-align: right;" }, template: function (e) { return format_currency(e, "Amount"); } },
Javascript:

var currency = new Intl.NumberFormat('en-US', {
    style: 'currency',
    currency: 'USD',
    minimumFractionDigits: 2,
});

function format_currency(e, property) {
    if (e[property] < 0) {
        return "<span class='negative_field'>" + currency.format(e[property]) + "</span>";
    }
    else if (e[property] === 0) {
        return "<span class='include_spaces'>$    -    </span>";
     }
     else {
        return "<span class='positive_field'>" + currency.format(e[property]) + "</span>";
    }
};
你是这样做的:

剑道格网

{ field: "Amount", title: "Balance", attributes: { style: "text-align: right;" }, template: function (e) { return format_currency(e, "Amount"); } },
Javascript:

var currency = new Intl.NumberFormat('en-US', {
    style: 'currency',
    currency: 'USD',
    minimumFractionDigits: 2,
});

function format_currency(e, property) {
    if (e[property] < 0) {
        return "<span class='negative_field'>" + currency.format(e[property]) + "</span>";
    }
    else if (e[property] === 0) {
        return "<span class='include_spaces'>$    -    </span>";
     }
     else {
        return "<span class='positive_field'>" + currency.format(e[property]) + "</span>";
    }
};

模板中存在语法错误:

template: "<font class='#if(Amount < 0) {# negative_field #} else {# positive_field #}'></font>"
                                                        Hash(#) should be closes here ^ 
template: "<div class='currency # if(Amount < 0) {#negative_field# } else { #positive_field# } #'>#=kendo.toString(Amount, 'c') #</div>"
但是,不要使用
font
,而是使用
div
并从要在模板中使用的列中删除
format
属性:

template: "<font class='#if(Amount < 0) {# negative_field #} else {# positive_field #}'></font>"
                                                        Hash(#) should be closes here ^ 
template: "<div class='currency # if(Amount < 0) {#negative_field# } else { #positive_field# } #'>#=kendo.toString(Amount, 'c') #</div>"

模板中有语法错误:

template: "<font class='#if(Amount < 0) {# negative_field #} else {# positive_field #}'></font>"
                                                        Hash(#) should be closes here ^ 
template: "<div class='currency # if(Amount < 0) {#negative_field# } else { #positive_field# } #'>#=kendo.toString(Amount, 'c') #</div>"
但是,不要使用
font
,而是使用
div
并从要在模板中使用的列中删除
format
属性:

template: "<font class='#if(Amount < 0) {# negative_field #} else {# positive_field #}'></font>"
                                                        Hash(#) should be closes here ^ 
template: "<div class='currency # if(Amount < 0) {#negative_field# } else { #positive_field# } #'>#=kendo.toString(Amount, 'c') #</div>"

谢谢你;这是Telerik告诉我的另一种方法:@xin太棒了!几乎和我提议的一样。别忘了在这里标出更好的答案;这是Telerik告诉我的另一种方法:@xin太棒了!几乎和我提议的一样。别忘了在这里标出更好的答案。