English 中文(简体)
我如何利用Knockout.js foreach binding来激发这种“JSON”观点模式?
原标题:How do I iterate this JSON view model using Knockout.js foreach binding?

我试图利用Knockout.js从Bing AP处获得JSON的回复。 下面是我的javascript代码和相应的Knockoutjs在html中具有约束力的Im。 我还对试图进入的物体Im进行了筛选。 从物体上看,我需要获得Thumbnail。 敦促并将此价值分配给人权基金会在该网页上的属性。 难道有人会发现我已经做错了吗? 我认为,这个问题在我的严格约束中可能是可能的。

JS

function bindModel(data) {
var viewModel = ko.mapping.fromJSON(data);
ko.applyBindings(viewModel);

}

$.ajax({
                url: fullUri,
                type:  post ,
                dataType:  jsonp ,
                jsonp: true,
                jsonpCallback:  searchDone ,
                success: function(data, textStatus, jqXHR){
                    console.log(data);
                    bindModel(data);
                }
})

传真

    <ul class="thumbnails" data-bind="foreach: Image.Results">
    <li class="span2"><img data-bind="attr: {href: Thumbnail.Url}"></img></li>
    </ul>

CEOLE SCREENSHTA

“entergraph

最佳回答

共同点。

如果你直接把该物体装入你的ole子,那么你将需要从财产编码/code>中查询,因为这将是你认为的第一份财产。

另外,图像标签通常为自我封闭、小控制,但并不使用<条码>。 相反,你应当制定<条码>src。

正确的标记是。

<ul class="thumbnails" data-bind="foreach: SearchResponse.Image.Results">
    <li class="span2"><img data-bind="attr: {src: Thumbnail.Url}" /></li>
</ul>

我认为,你使用制图图谱,应当从JS中加以利用,因为我确信,单单单单单单单单单单 j都会把 j子打成一个物体,因此,你的数据价值在目前还不是原始的。

因此,正确的约束方法就是这样。

function bindModel(data) {
    viewModel = ko.mapping.fromJS(data);
    console.log(viewModel);
    ko.applyBindings(viewModel);
}

这里是一个dle。

http://jsfiddle.net/madcapnmckay/udDGP/

希望这一帮助。

问题回答

<代码>mg tags use src undhref。 页: 1 Url }





相关问题
How to go from DOM node to viewModel object?

When the drop function is called back, this is set to the droppable DOM node (the target) and ui.draggable is the DOM node which was dragged. Is there an idiomatic way of getting the model object ...

making fields observable after ajax retrieval in knockout.js

I am wondering how I can make certain fields observables in knockout.js that I get from an ajax call without having to define the whole object in my viewmodel. Is this possible? Here is what I have ...

ASP.NET MVC Validation with jQuery $.ajax

I have a situation where I am sending data to a Controller via jQuery $.ajax, the data is a serialized json string. (MVC 3.0) It binds it fine - my controller receives the results and they are ...

Knockout.js and MVC

Just started playing with knockout.Js which is a fantastic framework Steve s really done well with that one. One thing I can t seem to do at the minute is impliment it with my Html Helpers. So for ...

Anyone using Knockoutjs with asp.net-mvc in anger? [closed]

I find it very interesting and have a prototype working based on Steve s mvc sample and another small sample from this thread. Using json.net to deserialize within the post action as I couldn t ...

热门标签