“与"在 AngularJS 中绑定 KnockoutJS? [英] The "with" binding of KnockoutJS in AngularJS?

查看:24
本文介绍了“与"在 AngularJS 中绑定 KnockoutJS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚从 KnockoutJS 切换到 AngularJS,但在 AngularJS 中找不到 KnockoutJS 的with"数据绑定.

I have just switched from KnockoutJS to AngularJS and I am not able to find the KnockoutJS's "with" data-bind in AngularJS.

这是 KnockoutJS 中的一段代码.with"绑定创建一个新的绑定上下文,以便后代元素绑定在指定对象的上下文中.

Here is the piece of code in KnockoutJS. The "with" binding creates a new binding context, so that descendant elements are bound in the context of a specified object.

<h1 data-bind="text: city"> </h1>
<p data-bind="with: coords">
    Latitude: <span data-bind="text: latitude"> </span>,
    Longitude: <span data-bind="text: longitude"> </span>
</p>

<script type="text/javascript">
    ko.applyBindings({
        city: "London",
        coords: {
            latitude:  51.5001524,
            longitude: -0.1262362
        }
    });
</script>

AngularJS 有没有类似上下文的东西?

Does AngularJS have anything like context?

推荐答案

我所知道的一切都没有......这是我能做的最好的:

Nothing like with that I know of.. this is the best I could do:

<h1>{{city}}</h1>
<p ng-repeat="c in [coords.or.possibly.deeper.in.tree]">
    Latitude: {{c.latitude}},
    Longitude: {{c.longitude}}
</p>

这篇关于“与"在 AngularJS 中绑定 KnockoutJS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆