gpt4 book ai didi

javascript - 将对象传递给挖空 View

转载 作者:行者123 更新时间:2023-11-30 18:02:32 25 4
gpt4 key购买 nike

我可以用 knockout 执行这样的绑定(bind)吗

<div data-bind="attr:{id: id,'data-plugin-options': options}">

我的模型看起来像

var model = {
id: id,
options: {
headerText: 'Group',
headerStyle: 'groupWithBorders'
}
};

ko.applybindings(model);

目前,在绑定(bind)发生后,我在数据插件选项上获得 [object object]。

最佳答案

Knockout 使用 toString() 将 attr 绑定(bind)中的对象转换为字符串。您可以重载该函数以输出您想要的结果:

var model = {
id: id,
options: {
headerText: 'Group',
headerStyle: 'groupWithBorders',
toString: function() {
return JSON.stringify(this);
}
}
};

关于javascript - 将对象传递给挖空 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16590957/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com