我正在尝试打印数据对象,但控制台只向我显示内部单词。我附上了当前问题的图像。此代码的概念是获取输入元素内的值并存储在对象中。我目前正在使用Ractive.js。
HTML:
<div class="form-element-container">
<label>Company Name <span class="required">*</span></label>
<input type="text" class="form-text full-width" placeholder="Enter the company name" id="accountName" value="{{leadData.accountName}}"/>
</div>
<div class="form-element-container default-cta-container">
<a class="button cta" on-click="addLead">Create Account</a>
</div>
使用Javascript:
app.on('addLead', function(event) {
var lmsleadData = {}
var data = app.get('leadData');
var proxy = app.get('proxy');
var endpoint = 'account/leads/';
var rt = 'POST';
var url = proxy+'?endpoint='+endpoint+'&rt='+rt;
function setvalueData(leadData, data) {
var lmsleadData = {
"isProfiled": false,
"isBaluarte": false,
"isVertical": false,
"isAffiliate": false,
"isBranch": false,
"id": 0,
"dateRequested": "2017-01-12",
"accountIdFk": 0,
"accountLeadId": 0,
"accountName": leadData.accountName,
"assignedEmployeeIdFk": 0,
"unitNumber": "34",
"floorNumber": "30",
"buildingName": "Test bldg name 34",
"streetNumber": "123",
"streetName": "Test street name",
"barangayIdFk": 0,
"cityTownIdFk": 0,
"provinceIdFk": 0,
"regionIdFk": 0,
"leadsIdentifier": "Test leads",
"salesRegion": "Test sales",
"egApproval": "string",
"smsId": "string",
"dateComSmsId": "2017-01-12",
"egRemarks": "string",
"dateComGbuTag": "2017-01-12",
"sgRemarks": "string",
"taggingDetailsIdFk": 0,
"profiling": "string",
"dateCompletedGbuTag": "2017-01-12",
"gbuTagidFk": 0,
"longitude": 0,
"latitude": 0,
"numberOfEmployees": "string",
"tier": "string",
"industryTypeIdFk": 0,
"gbuMigration": "string",
"finalReco": "string",
"motherAccountId": 0,
"remarksFindings": "string",
"finalCompanyName": "string",
"accountCategoryIdFk": 0,
"sourceLeadIdFk": 0,
"baluarte": false,
"vertical": false,
"affiliate": false,
"branch": false,
"profiled": false,
};
};
console.log(lmsleadData);
});
答案 0 :(得分:0)
从setvalueData函数中的变量中删除var
,因为它正在创建一个新的范围变量,您要更新现有变量:
function setvalueData(leadData, data) {
lmsleadData = {
"isProfiled": false,
"isBaluarte": false,
"isVertical": false,
"isAffiliate": false,
"isBranch": false,
"id": 0,
"dateRequested": "2017-01-12",
"accountIdFk": 0,
"accountLeadId": 0,
"accountName": leadData.accountName,
"assignedEmployeeIdFk": 0,
"unitNumber": "34",
"floorNumber": "30",
"buildingName": "Test bldg name 34",
"streetNumber": "123",
"streetName": "Test street name",
"barangayIdFk": 0,
"cityTownIdFk": 0,
"provinceIdFk": 0,
"regionIdFk": 0,
"leadsIdentifier": "Test leads",
"salesRegion": "Test sales",
"egApproval": "string",
"smsId": "string",
"dateComSmsId": "2017-01-12",
"egRemarks": "string",
"dateComGbuTag": "2017-01-12",
"sgRemarks": "string",
"taggingDetailsIdFk": 0,
"profiling": "string",
"dateCompletedGbuTag": "2017-01-12",
"gbuTagidFk": 0,
"longitude": 0,
"latitude": 0,
"numberOfEmployees": "string",
"tier": "string",
"industryTypeIdFk": 0,
"gbuMigration": "string",
"finalReco": "string",
"motherAccountId": 0,
"remarksFindings": "string",
"finalCompanyName": "string",
"accountCategoryIdFk": 0,
"sourceLeadIdFk": 0,
"baluarte": false,
"vertical": false,
"affiliate": false,
"branch": false,
"profiled": false,
};
};
答案 1 :(得分:0)
该变量超出了console.log()的范围。 将console.log()移动到函数
中function setvalueData(...) {
var lmsleadData = {
// ...
console.log(lmsleadData);
}
严格地说,通过省略声明前面的var,也可以使lmsleadData全局可见。但是应尽可能避免全局变量。
// ...
lmsleadData = {
// ...
另请注意,您永远不会调用setvalueData()