observableArray is not defined
observableArray is not defined
我在客户端开发环境中工作,必须遵守他们的编码标准。我有以下JS和HTML。我的observableArray是未定义的。我无法使它工作。甚至console.log也在打印正确的值。
请不要担心ko.applyBindings
。它得到了照顾。
我的JS代码:
define(
['knockout'],
function (ko) {
"use strict";
return {
onLoad: function (widget) {
widget.getDetails= function (prod) {
var abc = prod.DetailsNumbers();
console.log(abc);
var someArray= [];
someArray= abc.split(',');
//console.log(someArray);
var anotherObservableArray = ko.observableArray();
for (var i = 0; i < someArray.length; i++) {
var temp = {
"prodName": ko.observable(someArray[i])
};
anotherObservableArray.push(temp);
}
console.log(anotherObservableArray());
};
}
}
}
);
我的HTML代码:
<div id="someId">
<table>
<tbody>
<tr>
<td>Button Here</td>
<td><button data-bind="click: getDetails(product())">Click me</button></td>
</tr>// this here is working fine
</tbody>
</table>
<ul data-bind="foreach: anotherObservableArray"> // this doesnt work
<li>
<span data-bind="text: prodName"> </span>
</li>
</ul>
</div>
另一个ObservableArray未定义
您不会在声明anotherObservableArray
的函数范围之外公开它。基本上,您的代码是这样的格式:
{
onLoad: function (widget) {
widget.getDetails = function (prod) {
var anotherObservableArray = ko.observableArray();
// push some items into the array
console.log(anotherObservableArray());
};
}
}
您需要以某种方式在函数外部公开anotherObservableArray
。例如:
{
onLoad: function (widget) {
widget.getDetails = function (prod) {
var anotherObservableArray = ko.observableArray();
// push some items into the array
console.log(anotherObservableArray());
this.anotherObservableArray = anotherObservableArray; // Expose it on the function
};
}
}
将var anotherObservableArray = ko.observableArray();
移动到VM定义中,并确保它是公开的(即"public")。我想你确实有这样的东西:
var vm = {
// ...
// most likely you are exposing getDetails() already
// ....
anotherObservableArray: ko.observableArray()
};
// ...
ko.applyBindings(vm);
相关文章:
- reactRedux is not defined
- ReferenceError: not defined
- ReferenceError: cordova is not defined @ng-cordova.min.js:7
- jQuery is not defined - WordPress footer.php
- GAPI Is Not Defined
- Page_ClientValidate is not defined
- ReferenceError: $firebase is not defined
- ReferenceError: crimeID is not defined
- AngularJS: $scope is not defined?
- ajaxUrl is not defined
- WebView: Uncaught ReferenceError: Android is not defined
- ReferenceError SetInterval not defined
- ReferenceError: yes is not defined
- ReferenceError "not defined"
- Soundcloud API ReferenceError: $ is not defined (JavaScript)
- Angular: Compile is not defined
- nodeJS phantom ReferenceError: Promise is not defined
- observableArray is not defined
- Uncaught ReferenceError trapArea/Per is not defined
- ReferenceError: xmlhttp is not defined