我有这个变量持有数据
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属性分配给局部变量
答案 0 :(得分:1)
请尝试;
$scope.obj = {};
_.each(tooltipsJson, function( val, key ) {
$scope.obj[key] = val;
});
答案 1 :(得分:0)
如果要打印数组中对象的所有“文本”属性,请调用.each(),如下所示:
_.each(tooltipsJson, function(item){
console.log(item.Texts);
});