1
我正在做一個遊戲的JavaScript應用程序,目標是爲MMORPG製作一個「構建計算器」。我想將視圖與已存儲在我的應用程序中的數據同步。我搜索和測試不同的框架,和淘汰賽-JS似乎對我來說是最好的解決辦法Knockout,ViewModel內部的其他對象和數據綁定
HTML:
<script>
var simulatorTool = new SimulatorTool();
</script>
<body>
<p data-bind="text: test"> </p>
<p data-bind="text: test2"> </p>
</body>
的Javascript工具:
function SimulatorTool()
{
meSim = this;
this.config = new Config();
this.data = new Data();
this.stuff = new Stuff();
this.traits = new Traits();
this.view = new AppViewModel();
$(function(){
ko.applyBindings(meSim.view);
});
... functions
}
視圖模型:
function AppViewModel() {
this.test = "Test!";
this.test2 = ko.computed(function() {
return meSim.data.selectedData['profession']
}, this);
}
問題是,我不知道如何將html綁定到其他對象中的視圖。我甚至不知道是否有可能。我想要做這樣的事情
<p data-bind="simulatorTool.view, text: test"> </p>
如果沒有,我怎麼能訪問到內「SimulatorTool」的數據,如果畫面從應用程序分離?