2012-09-17 62 views
0

我是使用knockout2.1.0進行基因敲除的新手。 我有一個外部java腳本文件,但它不在我的html文件中調用。我不明白。無法在html中調用.js(使用基因敲除)

我已經加入我的HTML文件中的下列

<script src="Scripts/TestJavascript.js"></script> 

JS文件

///<reference path="~/Scripts/jquery-1.8.1.min.js"> 
///<reference path="~/Scripts/knockout-2.1.0.debug.js"> 
$(function AppViewModel() { 
this.firstName = ko.observable("rash"); 
this.lastName = ko.observable("Bertington"); 
this.fullName = ko.computed(function(){ 
    return this.firstName() + " " + this.lastName(); 
}, this); 
}) 
ko.applyBindings(new AppViewModel()); 

感謝。

+0

我的意思不是遇到苛刻,但你問題很混亂......你能提供一些更相關的代碼嗎? –

回答

5

您並未創建ViewModel。你傳遞給jquery。

嘗試

var AppViewModel = function() { 
    this.firstName = ko.observable("rash"); 
    this.lastName = ko.observable("Bertington"); 
    this.fullName = ko.computed(function(){ 
     return this.firstName() + " " + this.lastName(); 
    }, this); 
}) 
ko.applyBindings(new AppViewModel()); 
+0

謝謝。它現在工作完美。 – akeeseth

1

這段代碼必須出現在任何HTML界後,或在一個文檔準備事件(jQuery的)

function AppViewModel() { 
    this.firstName = ko.observable("rash"); 
    this.lastName = ko.observable("Bertington"); 
    this.fullName = ko.computed(function(){ 
     return this.firstName() + " " + this.lastName(); 
    }, this); 
}; 
ko.applyBindings(new AppViewModel()); 
+0

謝謝。他現在工作 – akeeseth