-
Notifications
You must be signed in to change notification settings - Fork 0
Quick Start
Maxime LUCE edited this page Apr 10, 2015
·
2 revisions
KoUnderscore can be used in many contexts ; AMD, CommonJS or as a global.
// app/main.js
require.config({
paths: {
knockout: 'path/to/knockout',
underscore: 'path/to/underscore',
kounderscore: 'path/to/kounderscore
}
});// app/viewmodel1.js
define(["kounderscore"], function(ko_) {
var obsArray = ko.observableArray([....]);
var regularArray = obsArray.filter(function(item) { ... });
var computedArray = obsArray._filter(function(item) { ... });
var customComputedArray = ko.computed(function() { return obsArray(); });
ko_.addToSubscribable(customComputedArray);
regularArray = customComputedArray .filter(function(item) { ... });
computedArray = customComputedArray ._filter(function(item) { ... });
});In order to have access to ko.observableArray underscore methods you should load KoUnderscore before creating ko.observableArray.
var ko_ = require("kounderscore");var obsArray = ko.observableArray([....]);
var regularArray = obsArray.filter(function(item) { ... });
var computedArray = obsArray._filter(function(item) { ... });
var customComputedArray = ko.computed(function() { return obsArray(); });
ko_.addToSubscribable(customComputedArray);
regularArray = customComputedArray .filter(function(item) { ... });
computedArray = customComputedArray ._filter(function(item) { ... });<script type="text/javascript" src="path/to/knockout.js"></script>
<script type="text/javascript" src="path/to/underscore.js"></script>
<script type="text/javascript" src="path/to/kounderscore.js"></script><script type="text/javascript">
var obsArray = ko.observableArray([....]);
var regularArray = obsArray.filter(function(item) { ... });
var computedArray = obsArray._filter(function(item) { ... });
var customComputedArray = ko.computed(function() { return obsArray(); });
ko_.addToSubscribable(customComputedArray);
regularArray = customComputedArray .filter(function(item) { ... });
computedArray = customComputedArray ._filter(function(item) { ... });
</script>