用于击倒数据绑定列表的引导弹出窗口
Bootstrap popover for a knockout data-bind list
我已经与淘汰赛和引导弹出窗口工作了几天,我有一个数据表,显示一些信息使用淘汰赛数据绑定。
<tbody data-bind="foreach: tehlist()">
<tr>
<td data-bind="text: $data.Category"></td>
<td data-bind="text: $data.Name"></td>
<td><button type="button" id="tehValue" class="btn btn-default" data-bind="text: $data.Value" style="border:none" onclick="getinfo()"></button></td>
</tr>
</tbody>
,当tehValue被点击时,它会触发一个函数,显示一个随机消息:
function getinfo(veh, item) {
$('#tehValue').popover({
content: 'Dana' + Math.random(),
html: true
});
}
问题是,它显示的弹出只为第一个点击值,而不是为其他的。
是否有一种方法来显示每个value
的数据绑定tehlist
不同的弹出窗口?
我已经改成:
<button type="button" id="tehValue" class="btn btn-default" data-bind="text: $data.Value, click: getinfo" style="border:none"></button></td>
和函数to:
getinfo = function (item, event) {
$('#tehValue').popover({
content: 'Dana' + Math.random(),
html: true
});
}
我仍然得到弹窗只为第一个值点击。
是否有一种方法来显示一个弹出窗口的按钮,而不使用Id,但只有onclick使用getinfo函数?
是下面的解决方案。http://jsfiddle.net/bdellinger/LkqTU/32342/
如何为你的弹出窗口做一个自定义绑定,比如
ko.bindingHandlers.popover = {
init: function(element, valueAccessor, allBindings, viewModel, bindingContext) {
ko.bindingHandlers.value.init(element, valueAccessor, allBindings);
var source = allBindings.get('popoverTitle');
var sourceUnwrapped = ko.unwrap(source);
$(element).popover({
trigger: 'focus',
content: valueAccessor(),
title: sourceUnwrapped
});
},
update: function(element, valueAccessor, allBindings, viewModel, bindingContext) {
var value = valueAccessor();
ko.bindingHandlers.value.update(element, valueAccessor);
}
};
,你的函数变成了一个被传递进来的ko。
this.getInfo = ko.computed(function() {
return this.name() + " " + Math.random()
}, this);
然后在HTML中像这样调用它
<button type="button" class="btn btn-lg btn-danger" data-toggle="popover" data-bind="popover: getInfo, popoverTitle: category">?</button>
下面是完整的解决方案,或者你可以直接点击上面的小提琴链接。
javascript。
ko.bindingHandlers.popover = {
init: function(element, valueAccessor, allBindings, viewModel, bindingContext) {
ko.bindingHandlers.value.init(element, valueAccessor, allBindings);
var source = allBindings.get('popoverTitle');
var sourceUnwrapped = ko.unwrap(source);
$(element).popover({
trigger: 'focus',
content: valueAccessor(),
title: sourceUnwrapped
});
},
update: function(element, valueAccessor, allBindings, viewModel, bindingContext) {
var value = valueAccessor();
ko.bindingHandlers.value.update(element, valueAccessor);
}
};
function teh(category, name) {
var self = this;
this.category = ko.observable(category);
this.name = ko.observable(name);
this.getInfo = ko.computed(function() {
return this.name() + " " + Math.random()
}, this);
}
function model() {
var self = this;
this.tehlist = ko.observableArray('');
}
var mymodel = new model();
$(document).ready(function() {
ko.applyBindings(mymodel);
mymodel.tehlist.push(new teh('car', 'honda'));
mymodel.tehlist.push(new teh('dog', 'pug'));
mymodel.tehlist.push(new teh('language', 'spanish'));
mymodel.tehlist.push(new teh('pc', 'dell'));
});
html <table class="table table-striped">
<thead>
<tr>
<th>Category</th>
<th>Name</th>
<th>Get Info</th>
</tr>
</thead>
<tbody data-bind="foreach: tehlist">
<tr>
<td>
<label data-bind="text:category" </td>
<td>
<label data-bind="text:name" </td>
<td>
<button type="button" class="btn btn-lg btn-danger" data-toggle="popover" data-bind="popover: getInfo, popoverTitle: category">?</button>
</td>
</tr>
</tbody>
</table>
<div>
相关文章:
- 在VanillaJS中模拟模型双向数据绑定
- Telerik rad组合框多列数据绑定
- 数据绑定:'系统Char'不包含名为'xxxxx'
- OnsenUI AngularJS数据绑定无法正常工作
- Ionic-item在导航栏中进行双向数据绑定
- 基本D3.js:如何将具有其他属性的数据绑定到元素
- 使用自定义数据属性或将数据绑定到处理程序来处理事件
- ListView的ItemTemplate内的自定义HtmlControl的数据绑定失败
- $http中的Angular 1数据绑定承诺不起作用
- 在何处和何时添加具有数据绑定的元素
- 使用AngularJs数据绑定的三元运算符显示图像
- 为什么针对工厂的Angular数据绑定只适用于函数
- 数据绑定上下文中的引导弹出窗口
- 如何将数据绑定到从 Angular 2 中的父窗口打开的子窗口
- AngularJS:打开新窗口,维护双向数据绑定
- 为什么数据与模态窗口解除绑定?/AngularJS.
- 显示数据绑定的bs模式窗口到角度ng重复
- 用于击倒数据绑定列表的引导弹出窗口
- 剑道窗口数据绑定不工作
- 如何在弹出jquery对话框窗口之前将数据绑定到图形