knockout.js를 클로저로 감싸려고했지만 매우 어렵습니다. 문제는 'this'변수에 대한 참조입니다. 난 포기하고 그냥 자바 스크립트를 사용하여 생각하고 있어요.clojurescript를 사용하여 knockout.js 래핑
나는 몇 가지 매크로를 쉽게 기능을 래핑하는 관리했습니다 http://knockoutjs.com/examples/helloWorld.html 및 http://knockoutjs.com/examples/contactsEditor.html
떨어져 예를 촬영했습니다. 예를 들어 :
var ViewModel = function() {
this.firstName = ko.observable("Bert");
this.lastName = ko.observable("Bertington");
this.fullName = ko.computed(function() {
// Knockout tracks dependencies automatically. It knows that fullName depends on firstName and lastName, because these get called when evaluating fullName.
return this.firstName() + " " + this.lastName();
}, this);
};
가된다 :
(defviewmodel data
(observing :first_name "Bert")
(observing :last_name "Bertington")
(computing :name [:first_name :last_name]
(str :first_name " " :last_name)))
그러나, 열심히처럼 뭔가 :
var BetterListModel = function() {
this.itemToAdd = ko.observable("");
this.allItems = ko.observableArray(["Fries", "Eggs Benedict", "Ham", "Cheese"]); // Initial items
this.selectedItems = ko.observableArray(["Ham"]); // Initial selection
this.addItem = function() {
if ((this.itemToAdd() != "") && (this.allItems.indexOf(this.itemToAdd()) < 0)) // Prevent blanks and duplicates
this.allItems.push(this.itemToAdd());
this.itemToAdd(""); // Clear the text box
};
this.removeSelected = function() {
this.allItems.removeAll(this.selectedItems());
this.selectedItems([]); // Clear selection
};
this.sortItems = function() {
this.allItems.sort();
};
};
ko.applyBindings(new BetterListModel());
나는 다음과 같은 코드를 일치하도록 clojurescript에서 무엇을 할 수 있는지 확실하지 않다 : this.allItems.push(this.itemToAdd())
의견이 있으십니까?
Keming Labs에서 내부적으로 사용하고있는 Knockout.js에서 영감을 얻은 Compute-Observables 라이브러리를 한 달 간 열어두면 공개됩니다. 나의 Github (@lynaghk)을 주시하십시오. –
감사합니다. 케빈! 나는 정말로 도서관을 가지고 노는 것을 고대하고있다. 그러나 clojure에는없는 다른 내부 변수에 액세스하는 변수를 선언하는 것과 비슷한 유형의 문제가있는 너무 많은 훌륭한 자바 스크립트 라이브러리가 있습니다. js와 clj 사이를 보간하는 명확한 방법이 중요하다는 생각이 듭니다. clojurescript ande javascript를 사용할수록 js 라이브러리가 눈에 띄지 않게됩니다 ... clojure를 배운 후에 연결 만 보았습니다. 어쨌든, 내 대답에 대한 귀하의 의견을 아래에 – zcaudate
잡아 주길 바래 http://fluentsoftware.github.com/cljs-binding/, 노크 아웃으로 성숙하지,하지만 .. – edtsech