[英]kendo requirejs access viewmodel from another module
如何從另一個requirejs模塊中“獲取”和“設置”一個視圖模式的屬性?
test.js
================
define(['kendo'],
function (kendo) {
var vm = kendo.observable({
propertyA: "a"
});
return {vm: vm};
});
another.js
================
define(['kendo'],
function (kendo) {
var testMethod = function () {
var test = require(['test']);
var testName = test.vm.get("propertyA"); //<< uncaught typeerror ???
test.vm.set("propertyA", "b"); //<< uncaught typeerror ???
};
return {testMethod: testMethod};
});
抱歉,因為我有ac#背景,除非我當前的項目,否則不習慣使用js。
我應該在test.js vm中添加方法以獲取和設置viewModel的屬性,還是可以通過其他方法直接從另一個模塊獲取並設置屬性(此示例中為propertyA)?
您無法按照自己的方式來做。 您對require
調用是異步的 。 因此test
將不會具有您想要的價值。
您可以這樣做:
define(['kendo', 'test'], function (kendo, test) {
var testMethod = function () {
var testName = test.vm.get("propertyA"); //<< uncaught typeerror ???
test.vm.set("propertyA", "b"); //<< uncaught typeerror ???
};
return {testMethod: testMethod};
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.