I am using knockout where I get my JSON object using Ajax. My question is how do I use this data in my own javascript code:
我正在使用knockout,我使用Ajax获取我的JSON对象。我的问题是如何在我自己的javascript代码中使用这些数据:
I have my mapped item, which is what I get returned from the ajax. Example:
我有我的映射项,这是我从ajax返回的。例:
MedarbejderId: ko.observable(element.MedarbejderId),
MedarbejderId is the Id I need to find the name in my following method.
MedarbejderId是我需要在以下方法中找到名称的ID。
function TranslateMed(i)
{
console.log("test " + i) // for testing purposes in console.
for (var key in obj)
{
if (obj[key].Value == i)
{
console.log("vi er inde");
return obj[key].Text;
}
}
return obj[0].Text
}
obj is my List of names. this works fine. My issue comes when i save the Data,
obj是我的名单。这很好用。当我保存数据时出现问题,
$(document).on("click", ".kout-update", null, function (ev) {
var current = ko.dataFor(this);
console.log(current);
current.MedarbejderNavn = TranslateMed(current.MedarbejderId);
current.Mode("display");
saveData(current);
});
here my current.MedarbejderId is c(){if(0<arguments.length)return c.Ua(c[F],arguments[0])&&(c.ia(),c[F]=arguments[0],c.ha()),this;a.l.sc(c);return c[F]}
这里我的current.MedarbejderId是c(){if(0
I need to get the Value of it instead.
我需要获得它的价值。
1 个解决方案
#1
0
The solution i found was that i needed to treat
我发现的解决方案是我需要治疗
current.MedarbejderNavn = TranslateMed(current.MedarbejderId);
Diffrently, so when i changed it to:
不一致,所以当我把它改成:
current.MedarbejderNavn = TranslateMed(current.MedarbejderId());
#1
0
The solution i found was that i needed to treat
我发现的解决方案是我需要治疗
current.MedarbejderNavn = TranslateMed(current.MedarbejderId);
Diffrently, so when i changed it to:
不一致,所以当我把它改成:
current.MedarbejderNavn = TranslateMed(current.MedarbejderId());