Created
July 2, 2013 20:58
-
-
Save cjblomqvist/5913048 to your computer and use it in GitHub Desktop.
See http://cjblomqvist.com/blog/Derby-Issue-with-arraylike-bindings-in-the-view-and-workaround/28 for info
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var app = require('derby').createApp(module) | |
; | |
app.get('/*', function(page, model, params) { | |
model.set('_page.unplannedOrder', [{"id":"1"}, {"id":"2"}, {"id":"3"}]); | |
page.render(''); | |
}); | |
app.enter('/*', function (model) { | |
model.remove('_page.unplannedOrder', 0); | |
model.set('_page.selected.3', true); // Triggers red backround on wrong li on the top ul (li above - aka #2) | |
}); | |
app.view.fn({ | |
/** | |
* Alternative to the buggy binding-implementation of myPath[myKey] | |
* E.g. where: | |
* myKey = 1 | |
* myKey2 = 0 | |
* {multiplePartPath(myPath, myKey, "property", mySecondKey)} | |
* will result in a dynamic version of: | |
* {myPath.1.property.1} | |
* @param {Object} basePath The base path already converted to an object (e.g. the path without quotes) | |
* @param {String/Key} leaf A leaf as a string, either directly or indirectly through a variable (which thus will be converted to a string through Derby) | |
* @return {Value} The returning value | |
*/ | |
multiplePartPath: function (basePath) { | |
var argumentsLength = arguments.length | |
; | |
for(var i = 1; i < argumentsLength && typeof basePath !== 'undefined'; i++) { | |
basePath = basePath[arguments[i]] | |
} | |
return basePath; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment