为了让我的 Angular 数据绑定(bind)完美工作,我需要将所有值合并到一个 JSON 文件中。我尝试过 $.extend(),它给出以下输出
需要一个解决方案
例如,如果我的回复如下所示:
[0:"{'test':'test'}", 1:"{'test':'test'}", 2:"{'test':'test'}",3: "{'test':'test'}"];
我需要的输出是:
{ test':'test', 'test':'test', 'test':'test', 'test':'test' }
编辑: 最终值将自动关联到 ng-model。
所需的输出示例:
{
"unique_id": 172,
"portfolio": "DIGITAL",
"bus_unit": "dummy",
"project_phase": "",
"test_phase": "SIT",
"project": "Google",
"golivedate": "03/09/2016",
"performance": "Green",
"summary": "jgnbfklgnflknflk",
"last_updated": "",
"risks_issues": "gfmngfnfglkj",
"project_start": "03/16/2016",
"batchLast_run": "",
"custom_project": "1",
"test_execution_id": 5456,
"unique_id": 172,
"test_execution_id": 5456,
"pass": 8,
"fail": 8,
"blocked": 8,
"in_progress": 8,
"no_run": 8,
"not_available": 0,
"total": 8
}
最佳答案
据我了解,您正在尝试将 Json 数据数组转换为单个 json 数据。因此,您有一组值,但您希望将所有值都放在一个变量中。试试这个
var testData = ["{'test':'test'}", "{'test':'test'}", "{'test':'test'}", "{'test':'test'}"];
var finalData ="";
$.each(testData,function(index,value){
finalData += value +',';
});
finalData = finalData.replace(/\},\{/g,',').slice(0, -1);
document.write(finalData);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
关于javascript - 格式化 JSON 以进行 Angular 数据绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36262056/