-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
can we define a variable when using containerless control flow syntax in knockoutjs #1002
Comments
I'm not sure what exactly you're asking for, but if you mean using the
|
I want this:
(i want this , how to accomplish it, i want to place the value in a variable and use further down)
|
Here's a binding I use: ko.bindingHandlers['let'] = {
'init': function(element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) {
// Make a modified binding context, with extra properties, and apply it to descendant elements
var innerContext = bindingContext.extend(valueAccessor);
ko.applyBindingsToDescendants(innerContext, element);
return { controlsDescendantBindings: true };
}
};
ko.virtualElements.allowedBindings['let'] = true; You can then use it like this: <!-- ko let: { strName: person.name } -->
...
<!-- ko if: strName === person.name -->
<span data-bind='text: person.name'></span>
<!-- /ko -->
...
<!-- /ko --> |
Great, that is perfectly what i was looking for! |
@mbest can this binding be implemented for Knockout 3.4+? I've seen several issues with it when I tried to use it in a real application (in particular, it didn't update the variable in some cases). |
It will be included in 3.5.0, whenever we manage to get that out. I just updated the comment above to use the latest version. The change was from |
@mbest Awesome, thank you for the quick answer! I'll try to test it shortly. |
@mbest Just FYI, the above binding works & fixes all my issues. Thanks! |
The text was updated successfully, but these errors were encountered: