简体   繁体   English

Knockout.js数据绑定到单独的变量中

[英]Knockout.js Data-bind into separate variables

I'm new to this and trying to get my head around the following scripts. 我对此并不陌生,并尝试着理解以下脚本。

http://jsfiddle.net/GSSCD/203/ http://jsfiddle.net/GSSCD/203/

Here is the HTML 这是HTML

<ul data-bind="foreach:servers">
<li> <a href="#" data-bind="text:name,attr:{href: 'http://'+name}">tester</a> <span data-bind="text:status,css:status"></span>

</li>

Currently this code along with the javascript from the link retrieves the status of certain servers and outputs it to an html webpage. 当前,此代码以及链接中的javascript检索某些服务器的状态并将其输出到html网页。 Unfortunately for me it outputs all the data in one hit onto the webpage using Data-bind. 不幸的是,我使用Data-bind一键将所有数据输出到网页上。

Is it at all possible to put each piece of data into its own variable which i can then use as i wish? 是否有可能将每个数据放入其自己的变量中,然后我可以根据需要使用它们?

So the first server name is put into a variable, then its status is put into a different variable then the second server name is placed into another variable etc.. for all the servers in the list. 因此,对于列表中的所有服务器,将第一个服务器名称放入一个变量中,然后将其状态放入另一个变量中,然后将第二个服务器名称放入另一个变量中,依此类推。

I really hope someone can help as i have been staring at this for the last 3 days and not really getting anywhere. 我真的希望有人能帮上忙,因为我在过去三天一直盯着它,却一无所获。

There is no easy Knockout way of doing it. 没有简单的淘汰方法。 You're either going to have to access the url with an ajax request and parse the returned html or maybe manipulate the DOM after it is updated to grab the info you need and populate your variables. 您将不得不使用ajax请求访问url并解析返回的html,或者在更新后的DOM中操作DOM以获取所需的信息并填充变量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM