[英]How to use underscore.js to assign an object to $rootscope?
我有這個變量保存數據
var tooltipsJson = [{
"Language": "en-GB",
"Section": "Sales&Marketing",
"ItemName": "CalculationType",
"Texts": "Having selected the account heading select the calculation ..."
},
{
"Language": "en-GB",
"Section": "Taxes",
"ItemName": "Save",
"Texts": "The Master Tax Table has been pre populated with the current UK, ..."
}
];
我想每個使用underscore.js
_.each(.........)
所以當我把:
console.log({{tooltipsJson.Taxes.Save}});
顯示文字
主稅表已預先填充了當前的英國,...
我希望將Texts屬性分配給局部變量
請試試;
$scope.obj = {};
_.each(tooltipsJson, function( val, key ) {
$scope.obj[key] = val;
});
如果要打印數組中對象的所有“文本”屬性,請按以下方式調用.each():
_.each(tooltipsJson, function(item){
console.log(item.Texts);
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.