如何將我的devices
屬性設置爲從/store.aspx/GetDevices
返回的數據。使用this.devices
不起作用。參考控制器屬性與控制器作爲語法
var app = angular.module("storeApp", []);
app.controller("storeController", ['$http', function ($http) {
this.devices = hardcodeddevices;
$http.post("/store.aspx/GetDevices", {})
.success(function (data) {
//this.devices = JSON.parse(data.d);
});
}]);
var hardcodeddevices = [...
像這樣'函數(data){ //this.devices = JSON.parse(data.d); } .bind(this)' – Grundy
或將_this_賦值給某個變量並使用它 – Grundy
[將正確的「this」上下文傳遞給setTimeout回調?](http://stackoverflow.com/questions/2130241/pass-correct -this-context-to-settimeout-callback) – Grundy