我在我的SharePoint列表中有一個貨幣字段類型的字段。我需要以列表的形式顯示列表中的所有項目。但是對於貨幣領域,它只顯示數字。我需要將值顯示在SP列表中。像432,98.00美元。我的代碼如下所示如何使用Javascript獲取SP貨幣字段類型值
var list = web.get_lists().getByTitle(listName);
var caml = new SP.CamlQuery();
caml.set_viewXml("<View><Query><OrderBy><FieldRef Name='" + columnName + "' Ascending='False'/></OrderBy></Query></View>");
var ascItems = list.getItems(caml);
context.load(ascItems);
//to get the value of each item based on field
var fieldType = fieldNames[i].get_fieldTypeKind();
if (fieldType === SP.FieldType.currency) {
item = listItem.get_item(fieldNames[i].get_internalName());
}
在這裏,fieldNames是一個數組,其中我有所有列名。 該項目將數值返回爲43298之類的數字。請幫助
我會使用正則表達式 –
但是在JSlink中,我們可以使用get_item()函數,它將返回列表中的字段值。所以我期待在jsom中使用類似的方式,而不使用正則表達式。 –
謝謝@FlashThunder。最後,我用正則表達式來解決我的問題。 (fieldType === SP.FieldType.currency)var currency = listItem.get_item(fieldNames [i] .get_internalName());如果(fieldType === SP.FieldType.currency)var currency = listItem.get_item(fieldNames [i] .get_internalName()); if(currency!= null) item ='$'+ currency.toFixed(2).replace(/(\ d)(?=(\ d \ d \ d)+(?!\ d))/g,「$ 1」); } } –