0

I am facing a problem will reading a json string containing nested arrays.

{
    "invoiceSet": {
        "lines": [
            {
                "line": "Business Partner had two or more interactions in the last 30 days",
                "togState": "true",
                "links": [
                    {
                        "linktxt": "Interaction History",
                        "linkid": "IRHIST"
                    }
                ]
            },
            {
                "line": "Open CRC Complaints Exist",
                "togState": "false",
                "links": [
                    {
                        "linktxt": "Interaction History",
                        "linkid": "IRHIST"
                    }
                ]
            },
            {
                "line": "Open Complaints Exist",
                "togState": "true",
                "links": [
                    {
                        "linktxt": "Interaction History",
                        "linkid": "IRHIST"
                    }
                ]
            },
            {
                "line": "Business Partner is a landlord",
                "togState": "false",
                "links": []
            },
            {
                "line": "Remotes Business Partner",
                "togState": "true",
                "links": [
                    {
                        "linktxt": "Interaction History",
                        "linkid": "IRHIST"
                    }
                ]
            },
            {
                "line": "Recent move has occurred in the last 60 days",
                "togState": "false",
                "links": []
            }
        ]
    }
}

I am using ajax call to get this json in a string

var setJsonText = jQuery.ajax({ url: ajxUrl,
                                            cache: false,
                                            async: false,
                                            type:"POST",
                                            dataType: "html" }).responseText;
var sets = jQuery.parseJSON( setJsonText );

viewModel.invLines(sets.invoiceSet.lines)

And my viewmodel

var viewModel = {
           invLines: ko.observableArray([]),
};

HTML

<table width="100%" >
 <tbody data-bind="foreach: invLines" style="width:100%">
  <tr>
   <td data-bind="text: line"></td>
   <td>
    <ul data-bind="foreach:links">
     <li>
      <a><span  data-bind="text:linktxt"></span></a>
     </li>
    </ul>
 </tbody>
</table>

The line are getting correctly printed but problem in coming on corresponding links. Please let me know what m i doing wrong.

Thanks, Anshul Kaistha

4

1 回答 1

0

您的问题可能出在您的 ajax 调用中。为什么要以 HTML 格式获取数据,然后将其转换为 JSON?为什么不直接以 JSON 格式获取数据?

无论如何,这个 jsFiddle 演示了您的代码工作(减去 ajax 调用),因此您发布的所有绑定似乎都是有效的:

http://jsfiddle.net/unklefolk/g9Q9V/3/

希望这有助于解决您的问题。

于 2012-09-18T09:42:25.007 回答