私が取り組んでいるプロジェクトでは、やや複雑な XML ファイルで多くの作業が必要になるため、それらを SimpleXML 配列に変換し、JSON エンコードして、Ajax 経由で Knockout に渡します。
問題は、各プロパティのほとんどに属性があり、SimpleXML がそれを というオブジェクトに押し込むこと@attributes
です。のようにバインドしようとするとmyObject().@attributes.Name
、エラーが発生します
Message: SyntaxError: Unexpected token ILLEGAL;
Bindings value: text: alertObj().@attributes.Name
試してみ'@attributes', ['@attributes'], [@attributes]
ましたが、何も機能していません。また、さまざまなエスケープ文字と Unicode エスケープも試しました。
json は次のようになります。
var alertObject =
{
"@attributes":
{
"DescriptionContentType":"text\/plain",
"Description":"",
"IsActive":"true",
"Name":"Apache Requests Per Interval"
},
"Frequency":
{
"PeriodInSeconds":"60"
},
"MetricLevelNotification":"false",
"AlertTriggerMode":"2",
"CautionActionDelay":"0",
"DangerActionDelay":"0",
"CautionActionList":
{
"ActionID":
{
"ManagementModuleName":"Base Module",
"ConstructName":"Base SMTP Mail Action"
}
},
"DangerActionList":
{
"ActionID":
{
"ManagementModuleName":"Base Module",
"ConstructName":"Base SMTP Mail Action"
}
},
"MetricGroupingID":
{
"ManagementModuleName":"Base Module",
"ConstructName":"Apache Requests Per Interval"
},
"AlertCombineOperator":"1",
"AlertCompareOperator":"2",
"CautionTargetValue":"2000",
"DangerTargetValue":"15000",
"CautionMinNumPerPeriod":"3",
"CautionAlertPeriod":"6",
"DangerMinNumPerPeriod":"1",
"DangerAlertPeriod":"1"
};
構造と名前を変更することは避けたいと思います。
どうすればこれを機能させることができますか??