Javascript 如何将对象绑定到数组中

Javascript 如何将对象绑定到数组中,javascript,knockout.js,Javascript,Knockout.js,我有一个这样的物体 var users = [new User(),new User()]; var location = new Location(); 里面有另一个这样的物体 var users = [new User(),new User()]; var location = new Location(); 然后在我的视图中,我会绑定我的用户数组,当我绑定Location对象时,我不会为每个绑定键入“Location.MyProperty1”、“Location.MyPropert

我有一个这样的物体

var users = [new User(),new User()];
var location = new Location();
里面有另一个这样的物体

var users = [new User(),new User()];
var location = new Location();
然后在我的视图中,我会绑定我的用户数组,当我绑定Location对象时,我不会为每个绑定键入“Location.MyProperty1”、“Location.MyProperty2”,但我只会键入“MyProperty1”、“MyProperty2”

这不是一个bug,只是一个问题。 我可以使用knockout做这样的绑定吗?

有一个“with”绑定,它从一个对象创建一个新的绑定上下文:

<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>

纬度:, 经度:

ko.applyBindings({ 城市:“伦敦”, 协调:{ 纬度:51.5001524, 经度:-0.1262362 } });

摘自

您是如何绑定位置的?我的意思是,您使用foreach绑定位置吗?不,我使用foreachusers@xdumaine你是怎么看的并不难回答