From 834316a5a4150e1ea55c1868dd56349a0d1f834d Mon Sep 17 00:00:00 2001 From: "jason.zhu" Date: Thu, 27 May 2021 04:43:27 +0000 Subject: [PATCH] chap1->Observables to refresh the UI automatically->Computed observables (optimised) --- ko-cart/js/viewmodel.js | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/ko-cart/js/viewmodel.js b/ko-cart/js/viewmodel.js index bc5c32f..4f4c56d 100644 --- a/ko-cart/js/viewmodel.js +++ b/ko-cart/js/viewmodel.js @@ -35,16 +35,8 @@ var vm = (function () { } //filter data var filtered = ko.utils.arrayFilter(catalog(), function (item) { - var fields = ["name"]; // we choose to filter by name - var i = fields.length; - while (i--) { - var prop = fields[i]; - var strProp = ko.unwrap(item[prop]).toLocaleLowerCase(); - if (strProp.indexOf(filter) !== -1) { - return true; - } - } - return false; + var strProp = ko.unwrap(item["name"]).toLocaleLowerCase(); + return (strProp.indexOf(filter) > -1); }); return filtered; });