gpt4 book ai didi

javascript - 使用 Ractive.js 进行数组推送

转载 作者:行者123 更新时间:2023-11-28 07:43:43 24 4
gpt4 key购买 nike

我正在尝试使用 Ractive.js 将项目添加到数组中。这是我所拥有的...

<select value='{{selectedColumn}}'>
{{#colNames}}
<option value='{{this}}'>{{this}}</option>
{{/colNames}}
</select>

<select value='{{selectedLogic}}'>
{{#possibleLogic}}
<option value='{{this}}'>{{this}}</option>
{{/possibleLogic}}
</select>

<input value='{{searchVal}}'>

<button on-click='addFilter(selectedColumn, selectedLogic, searchVal)'>Add filter</button>

在 Ractive 对象中...

filterList = new Ractive({
el: 'container',
template: '#template',
data: {
items: myItems,
},
addFilter: function (cat, log, val) {
console.log("yo");
items.push({
description: cat + " " + log + " " + val,
completed: false
});
}
});

还尝试使用按钮调用此函数...

filterList.on({
new_filter: function ( cat, log, val ) {
console.log("hello");
items.push({
description: cat + " " + log + " " + val,
completed: false
});
},
});

这两种方法似乎都不起作用。 console.log() 甚至不会被调用。

谢谢

最佳答案

花了更多的时间,这似乎有效,但也许不是最好的解决方案......

filterList.on('testFunc', function(){
var tmp = (this.get("selectedColumn") + " " + this.get("selectedLogic") + " " + this.get("searchVal"))
items.push({description: tmp, completed: false})
});

以及按钮的代码...

<button on-click='testFunc'>Add filter</button>

关于javascript - 使用 Ractive.js 进行数组推送,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27694461/

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