我已经开始学习Knockout了,我在按钮点击过滤可观察数组并显示结果时遇到了一些麻烦.
这是我的模特:
function Product(data) {
this.id = data.id;
this.name = data.name;
this.price = data.price;
this.description = data.desc;
this.image = data.image;
this.genre = data.genre;
this.show = data.show;
this.offer_desc = data.offer_desc;
this.offer_id = data.offer_id;
}
function ProductModel() {
var self = this;
self.products = ko.observableArray([]);
$.getJSON('../PHP/Utilities.php?json=true', function(json) {
var mappedProducts = $.map(json, function(item) { return new Product(item) });
self.products(mappedProducts);
});
self.filterProducts = ko.computed(function(genre) {
if(typeof genre === 'undefined') {
return self.products(); //initial load when no genre filter is specified
} else { …
Run Code Online (Sandbox Code Playgroud) 我正在尝试学习javascript正则表达式而且我遇到了问题.
我正在尝试使用以下规则进行验证.
仅允许:
Numbers 0-9
(
)
+
-
(space)
Run Code Online (Sandbox Code Playgroud)
我已经拿出下面的正则表达式来处理这个:
/[0-9\)\(\+\- ]+/i
Run Code Online (Sandbox Code Playgroud)
以下匹配但不应该执行,因为它包含@符号:
+0@122 0012
Run Code Online (Sandbox Code Playgroud)
我正在使用以下测试:(返回true)
/[0-9\)\(\+\- ]+/i.test("+0@122 0012")
Run Code Online (Sandbox Code Playgroud)
谢谢.