[英]Why can't I change the value of a Json
I want to update the value "customer.signature" but my code does not do, what I want him to do. 我想更新值“ customer.signature”,但我的代码不执行,我想让他执行。 JSON and HTML are without errors, that influence what I want. JSON和HTML没有错误,影响了我想要的东西。 The problem is, my JS is not working. 问题是,我的JS无法正常工作。 "data.signature" is updating fine. “ data.signature”正在更新。 but "data.customer.signature" is not. 但是“ data.customer.signature”不是。
Json (which I get by rest "Accounts"): 杰森(我可以通过“帐户”获得它):
{
"signature": "newAccountSignatur",
"signatureEnabled": true,
"defaultMsisdn": "08282709909013",
"httpForwardingAddress": "http://null.dev.to",
"smtpForwardingAddress": "lazarus@null.dev.to",
"customer": {
"signature": "newCustomerSignatur",
"id": 10339,
"companyName": "Gerd Webapp Test v2.0.x",
"diallingCodeId": 43,
},
}
Js: Js:
$scope.saveSignature = function () {
if (AuthService.isAuth()) {
Accounts.one().get().then(
function (resultOk) {
resultOk.data.customer.signature = $scope.newCustomerSig;
resultOk.data.signature = $scope.newAccountSig;
$log.d("resultOk: ", resultOk.data);
resultOk.data.put().then(
function (resultOk) {
alert("Saved");
$log.d("Accountinfo ok: ", resultOk);
$scope.user = resultOk.data;
},
function (resultError) {
$log.d("Accountinfo error: ", resultError);
ErrorService.showApiError(resultError);
}
);
}
);
}
};
html: 的HTML:
<form name="signature" ng-sub>
<div>
<textarea rows="5" cols="40" ng-model="newAccountSig" ng-trim="false" placeholder="{{user.signature}}"></textarea>
</div>
<i> Persönliche Signatur </i><br/>
<div>
<i> Zweites Beispiel</i><br/>
<textarea rows="5" cols="40" ng-model="newCustomerSig" ng-trim="false" placeholder="{{user.customer.signature}}"></textarea>
</div>
<i>Information für mich: </i>
<p>Aktueller Wert in account.signature = </p>
<span>{{user.signature| stringIfBlank:'-'}}</span>
<p>Aktueller Wert in account.customer.signature = </p>
<span>{{user.customer.signature| stringIfBlank:'-'}}</span>
</form>
You can try this example : jsbin 您可以尝试以下示例: jsbin
var data ={
"signature": "newAccountSignatur",
"signatureEnabled": true,
"defaultMsisdn": "08282709909013",
"httpForwardingAddress": "http://null.dev.to",
"smtpForwardingAddress": "lazarus@null.dev.to",
"customer": {
"signature": "newCustomerSignatur",
"id": 10339,
"companyName": "Gerd Webapp Test v2.0.x",
"diallingCodeId": 43,
},
};
data.customer.signature="newsign";
console.log(data.customer.signature);
alert(data.customer.signature);
UPDATE the order of the nesting was the problem. 更新嵌套的顺序是问题所在。 for those who maybe have to handle familiar problems.. I wont remove this. 对于那些可能不得不处理熟悉的问题的人。我不会删除它。
$scope.saveSignature = function () {
if (AuthService.isAuth()) {
AccountCustomer.one().get().then(
function (resultOk) {
resultOk.data.signature = $scope.newCustomerSig;
resultOk.data.put().then(
Accounts.one().get().then(
function (resultOk) {
resultOk.data.signature = $scope.newAccountSig;
resultOk.data.put().then(
function (resultOk) {
alert("Saved");
$log.d("Accountinfo ok: ", resultOk);
$scope.user = resultOk.data;
},
function (resultError) {
$log.d("Accountinfo error: ", resultError);
ErrorService.showApiError(resultError);
}
);
}
));
}
);
}
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.